I use NSUserDefaults as following
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
BOOL downloaded = [prefs boolForKey:@"downloaded"];
if (! downloaded ) {
[self MoveAndBuild ];
[prefs setBool:YES forKey:@"downloaded"];
//////////// Write to the file to prevent re import at the next time .
开发者_Go百科 }
my question is can NSUserDefaults carry object of class , I mean I have a class and want to save object of it to be act as default is applicable , another question can NSUserDefaults store nsstring
any suggestion please
We use NSUserDefaults to store objects, and an object can be of any type i:e NSString, NSArray, Class Objects etc. For Storing you can use:
[defaults setObject:anyObject forkey:@"objectKey"];
Your custom class object needs to implement the NSCoding
protocol.
Check the below SO post.
How to store custom objects in NSUserDefaults
NSUserDefaults can store (and only store) plist-objects. please see http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/UserDefaults/UserDefaults.html for programming NSUserdefaults.
精彩评论