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!
Thread SafetyThe UserDefaults class is thread-safe.
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 .
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With