Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSUserDefaults vs CFPreferences, what to consider

Apple provides documentation for managing user preferences through both Core Foundation and Foundation Kit. It also doesn't offer any help with choosing one or another, except for stating that they're indeed different ("not toll-free bridged").

So, I'm interested, is there anything I should consider selecting configuration mechanism for the application? Or should I just toss a coin?

Thanks!

like image 291
Nikita Rybak Avatar asked Feb 03 '11 19:02

Nikita Rybak


People also ask

Is NSUserDefaults thread safe?

Thread SafetyThe UserDefaults class is thread-safe.

What types can you store natively in NSUserDefaults?

Types stored in NSUserDefaultsplist type can be stored by NSUserDefaults . These types are NSString(String) , NSArray(Array) , NSDictionary(Dictionary) (for both NSArray and NSDictionary types their contents must be property list objects), NSNumber(Int, Float, Double, Boolean) , NSDate and NSData .

What is NSUserDefaults?

NSUserDefaults are used to save small portions of data the App is dependent on to run correctly, while other approaches are good to store bigger amounts of data, that the app work with.

How do you save NSUserDefaults in Objective C?

static func setObject(value:AnyObject ,key:String) { let pref = NSUserDefaults. standardUserDefaults() pref. setObject(value, forKey: key) pref. synchronize() } static func getObject(key:String) -> AnyObject { let pref = NSUserDefaults.


1 Answers

You are supposed to use NSUserDefaults, which is absolutely the default choice. I suppose you could use CFPreferences, but unless you had a good reason to make that choice, I'd steer clear of CF-APIs.

like image 158
Jonathan Sterling Avatar answered Nov 15 '22 06:11

Jonathan Sterling