How do I select random element from an array? [closed] - objective-c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I ended up with the following plus a few modifications:
NSArray *Quotes = #[#"test1",#"test2"];
NSString *Quoteselected = arc4random() % [quotes];
self.label.text = Quoteselected;
I found the error, which probably also caused the SIGARBT -my randomization created values bigger than what I had element for in the array - thereby making the code try to pick elements not existing.
thanks for all the help

I think this is what you look for:
http://www.raywenderlich.com/934/core-data-tutorial-for-ios-getting-started
This is called core data that comes with Objective-C. It is what I use for small, LOCAL database.
On the other hand, for small to medium size of database for a starter like you (I presume you just started making programs?) Check out ruby on rails and AFNetworking library. BTW, this is ONLINE or REMOTE databse. (Just saying, but in ruby on rails, database can be created with using command line, you'll know how simple it is)
http://guides.rubyonrails.org/getting_started.html
Two options, you can choose either one.

Assuming you're okay with typing out every quote, you could use a property list
plist tutorial
Unless it's a very large database

Related

Bigquery: dbt seed with ARRAY fields [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'd like to load some small configuration table I have on BigQuery using seeds.
I did that successfully till now, but now I have a table with an array field.
I put the arrays in the usual BigQuery format ["blablabla"], but no luck.
I tried forcing the datatype in dbt_prject.yml, but I get a "ARRAY is not a valid value" error.
Did someone ever used seeding with structured fields?
Daniele
I don't think this is possible, unfortunately. From a little online research, this appears to be a joint limitation of:
the BigQuery LoadJobConfig API that dbt calls here
the CSV file format, which doesn't really have a way to specify a nested schema (related issue)
A long-term resolution to this may be support for JSON-formatted seeds (dbt#2365).
In the meantime, I recommend that you set the seed column type to string and convert it to an array (using json_extract_array) in a staging model.

Using NSArray<MyProtocol> and NSDictionaty<MyProtocol> [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I faced with two declaration NSArray<MyProtocol> and NSDictionary<MyProtocol>. I didn't find correct explanation of it and how work correct with it.
I think this may be related to a clever macro that did the rounds recently (possibly this one, there are a lot of similar projects on GitHub).
The values stored by NSArray and NSDictionary are of type id. This basically means that the type of the objects being stored is untyped. The problem with this is a that you loose type safety. The macro in question attempted to address this problem by creating a protocol that is applied to the array/dictionary so that the returned objects have a more specific type than id.
In Xcode you can find where <MyProtocol> is being declared by cmd+clicking on it <MyProtocol>.
Personally I would avoid using such macros. They are solving a problem, but the solution is not in keeping with the Objective-C ethos. I would solve this problem by one or more of the following:
ensuring the collection has a descriptive instance/variable name
creating another class that wraps the collection.

CoreData(iOS):Do I need to create a database to use CoreData ?Can coredata operate on a simple flat file? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am pretty new to CoreData Programming but would like to ask:
Do I need to create a database to use CoreData ? Can coredata operate on a simple flat file ?
Please provide suitable references & links.
Thanks in advance
Core Data provides four native types of persistent store:
SQLite
Binary
XML
In-Memory
These store types each offer different benefits and tradeoffs, and are described in “Persistent Store Features”. The Binary and XML stores are "atomic” stores—they must be read and written in their entirety, unlike the SQLite store which can be modified piecemeal, one record at a time if you wish.
Refer to the first link (pdf)

Expiring Data In Table View (Even After An App Is Closed And Restarted) (iOS) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need help being pointed in the right direction (to the right documentation or tutorial) since I don't know exactly what this programming would be filed under.
Basically, I saw an app that had a section of 'Deals' on food and drinks at stores. You had to use the app to redeem the deal, but you could only use the deal once. It seemed that the table view of deals was being populated by a PList from a server (because it is constantly updated) BUT when you choose a deal and use it, it disappears from the table view (because you claimed it).
Now I was thinking it could be coding using an if else statement declaring integer values (and if they weren't equal to the integer, then the deal wouldn't display) but that can't be the case because if I close out the app and reopen it, the deal still isn't in the list. Am I right in assuming that somehow the PList or database is being updated by the user interaction? Are databases for each user being created when someone downloads the app (or starts it)?
I'm kinda in the dark about it and trying to figure out how they pull this off. I'm not sure if I'm way off base and there is some sort programming that I'm possibly not even aware of. Any thoughts? Thanks!
You should investigate NSFetchedResultsController - it allows to perform a lot of pretty things with your data + database.
Check this tutorial.
Also, take a look at the Apple documentation.
Core data basics strongly required.

What is the difference between My.Computer.FileSystem.MoveFile and File.Move [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
The question says it all really.
What are the differences between these two methods that appear to carry out exactly the same function?
Is there guidance to say which should be used or are there conditions when you may use either?
The FileSystem.MoveFile has some more options than File.Move, like for example optionally showing a progress dialog, and creating the destination folder if it doesn't exist.
If you just want to move or rename a file, the File.Move method will be called in the end whichever you use, so calling it directly means slightly less overhead.
I believe they have near-identical functionality. Most people I've seen would prefer to use the latter, because "MyComputer." is a VB.NET-only construct, whereas File.Move is used in both C# and VB.NET. This makes it easier to get help, and easier for C# coders to read the VB.NET code and vice-versa.
I haven't checked My.Computer.FileSystem.MoveFile, but you can state if they are differences moving html files with associated images directories., because File.Move just move the file, but doesn't move the associated directory