Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-01-2010, 07:11 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 57
nexirius is on a distinguished road
Default Storing data

Dear all


I am new here and I checked out several tutorials to get in touch with the
Objective C.

Now I'm wondering how you prefer to store your data. Many people were
talking about SQLite, but until now I was "scared" to start with that as
I have not that much experience with Objective C.


Some hours ago I found this code example:

Code:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
[prefs setObject:@"TextToSave" forKey:@"keyToLookupString"]; 
[prefs synchronize];
I have successfully tested it and I wondered how this stuff is stored? When
I tried it on my iPod it seemed that this data is stored until you delete your
application. Is that really true?

When do people use this method? I guess if you have more data, you should
use SQLite?


Thanks for your answers! I'm looking forward to reading them!
nexirius is offline   Reply With Quote
Old 08-01-2010, 10:32 PM   #2 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 102
chrysb is on a distinguished road
Default

I use NSUserDefaults for storing simple data, such as preferences, or simple states.

For more complex things, like objects and arrays, I use local file storage. I created a key-based caching class that automatically saves things to disk and loads them again when the application starts. It's very convenient.

SQLite makes sense if you have a *lot* of data that you're storing on the phone and you need a relational database.
chrysb is offline   Reply With Quote
Old 08-01-2010, 10:36 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Tasmania, Australia
Posts: 195
Son of a Beach is on a distinguished road
Default

User defaults are easy and convenient. A great way for storing smaller amounts of data.

For larger amounts of data, you should look into CoreData (which usually uses SQLite internally, but abstracts you from it). It's essentially a persistence layer for objects.

Some object types (eg, NSArray, NSString, NSData) also have convenience methods for reading/writing themselves in their entirely to/from disk. NSKeyedArchiver can help with more complex/custom object classes too. Sometimes this can be useful, but CoreData or User defaults are usually better.
Son of a Beach is offline   Reply With Quote
Old 08-02-2010, 05:04 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 57
nexirius is on a distinguished road
Default

Wow thanks! Cool, I guess I understood it correctly thing then.

And these NSUserDefaults are stored as long as I delete, overwrite it or the
app is deleted? And I could also save Arrays to it?
nexirius is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 324
9 members and 315 guests
alexP, gordo26, headkaze, mistergreen2011, nobstudio, Objective Zero, rayjeong, revg, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:18 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0