PDA

View Full Version : What is preferred method of data storage?




darkpegasus
Aug 29, 2008, 06:46 PM
This may seem like a stupid questions, but I couldn't find an example of it anywhere. Is there a specific way that user preferences should be stored?

I basically have some simple attributes like a background image name that I would like to save and then load next time the user opens the app.



kainjow
Aug 29, 2008, 07:20 PM
NSUserDefaults

darkpegasus
Aug 29, 2008, 07:50 PM
Awesome, thanks. And for those that might need more than a one-word reply (although it's amazing what one word can tell you):

-(void)saveToUserDefaults:(NSString*)myString
{
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];

if (standardUserDefaults) {
[standardUserDefaults setObject:myString forKey:@"Prefs"];
[standardUserDefaults synchronize];
}
}

-(NSString*)retrieveFromUserDefaults
{
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *val = nil;

if (standardUserDefaults)
val = [standardUserDefaults objectForKey:@"Prefs"];

return val;
}

jsnuff1
Aug 30, 2008, 12:42 AM
I just save all the user info as an array within an NSData object on a file in documents directory.