tags:

views:

113

answers:

2

Is there any way to save data without connecting to server on the iPhone? If so, please describe how.

+4  A: 

Look at the NSUserDefaults class. It can save primitives and NSArray objects of primitives.

Example, your app might write out before app terminates in your app delegate:

[[NSUserDefaults standardUserDefaults] setString:@"Value" forKey:@"Key"];

And then read it in after launch:

NSString *dataYouNeed = [[NSUserDefaults standardUserDefaults] stringForKey:@"Key"];

Just remember to handle the nil case gracefully (i.e. that the app will keep working immediately after a fresh install or a reset to the user defaults).

Edit: the question has already been more-or-less rewritten. Obviously if you need to store data that will act as your application's model (in the MVC sense), Core Data or sqlite is where you would do best to start looking.

Justin Searls
A: 

If it's a small number of things, use NSUserDefaults. If it's a lot of stuff, use Core Data.

bpapa