views:

28

answers:

3

Hello friends..

For my current development of iphone app, I want to implement history/favorite feature. After lots of googling I came to conclusion that 'NSUserDefaults' would work better in case of short data storage. But still I am not clear how to interact with NSUserDefaults....Can anyone refer any example or article to work out with this requirement? Help appreciated...

Thanks

A: 

Usually, NSUserDefaults is only for Application Setting. This is the recommendation from Apple. You should consider it carefully.

This programming topic describes the programmatic interface for interacting with the Mac OS X user preferences system—also known as the user defaults system—using Cocoa. Preference settings let you offer ways for users to customize the appearance or behavior of your software. The user defaults system lets you access and manage user preferences. You can use the defaults system to provide reasonable initial values for application settings, as well as save and retrieve the user's own preference selections across sessions.

vodkhang
A: 

First read the NSUserDefaults Class Reference.

And here it is an example on how to use it:

// Saving info to defaults
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults setObject:myObj forKey:@"myKey"];

// Retrieving info from defaults
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults objectForKey:@"myKey"];

Depending on the kind of info that you want to store, you may be interested on have a look at NSKeyedArchiver, and use it to encode your objects before save them on the user defaults, or any other place.

vfn
A: 

Hey friends, thanks for the response and sorry for the delayed. Solution given by vfn actually worked for me and I also referred the reference for NSUserDefaults classes. But according to that I dont think I should use it, coz I need to store a big favorite list in my app. For that I need to store array. So I am now continuing with writing my history/favorite list into plist...Hope it will work. Thanks again

rohanparekh