开发者

can NSUserDefaults carry object of class

开发者 https://www.devze.com 2023-03-12 12:56 出处:网络
I use NSUserDefaultsas following NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; BOOL downloaded = [prefs boolForKey:@\"downloaded\"];

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号