I am creating one iOS app with the possibility of managing users and login them.
I want to persist the user data settings of every user but I´m not sure what is the best way to do save this setting by each user.
Should I save the data into an xml file, or NSUserDefaults or even saving them into my Parse Cloud Database?
I just want to save a list of user properties when loading a view, but I must have in consideration that my App must load the right parameter for current user.
For example:
User: Peter trackingSwitchEnabled: YES
User: Molly trackingSwitchEnabled: NO
User: Paul trackingSwitchEnabled: YES
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.
All the contents saved by NSUserDefaults is saved inside a plist file that can be found under Library -> Preferences -> $AppBundleId.
Currently, there is only a size limit for data stored to local user defaults on tvOS, which posts a warning notification when user defaults storage reaches 512kB in size, and terminates apps when user defaults storage reaches 1MB in size.
Core Data only fetches the information it needs to perform the requests the application makes. This is very different from the defaults system. The UserDefaults class loads the property list into memory to improve performance and it asynchronously writes the changes back to disk at appropriate times.
Bonus ASCII art!
NSUserDefaults plist Core Data SQList
Full text search ✘ ✘ ✘ ✔
Complex search ✘ ✘ ✔ ✔
Binary data ✘ ✘ ✔ ✔
Allows complex data ★ ★★ ★★★★ ★★★★
Performance ★ ★ ★★★ ★★★★
Learning curve ★ ★★ ★★★ ★★★★
If you want to use NSUserDefaults, you should use initWithSuiteName:
to create different database.
[[NSUserDefaults alloc] initWithSuiteName:USER_IDENTIFY
]
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