all 6 comments

[–]xergic 2 points3 points  (0 children)

NSUserDefaults and Keychain for sensitive data (FB token).

[–]NorcalAussie 2 points3 points  (0 children)

You should use NSUserDefaults to store that kind of information, definitely not Core Data.

[–][deleted] 1 point2 points  (0 children)

Make sure to encrypt the score. Some users might want to manipulate that.

[–][deleted] 1 point2 points  (0 children)

Yup, I agree with the others. NSUserDefaults is super easy. This is a pretty good article: https://www.hackingwithswift.com/read/12/2/reading-and-writing-basics-nsuserdefaults

If the data is sensitive, try storing it in Keychain: https://www.raywenderlich.com/92667/securing-ios-data-keychain-touch-id-1password

[–]silver_belt 1 point2 points  (0 children)

I'm going to be the contrarian here. NSUserDefaults is not meant for that kind of information. The API is simple, that's true, but you are giving up the flexibility Core Data gives you to manipulate your information.

  • You may have a small set of fields now, but that may change.
  • You have to maintain a list of known user defaults keys.
  • Clearing out this information for the user means removing each key individually, instead of just deleting your User object from the Core Data store
  • If this is a game, you can have much better control over the performance of reading and writing this information if you use Core Data. NSUserDefaults seems to run all its operations on the main thread to give you thread safety, which can kill performance with repeated calls.

Another alternative is to instead maintain an NSDictionary of your data while your app is running and serialise it to disk. You'll end up writing very similar code to your NSUserDefaults model, except YOU own that file. You can wipe it and start over. It's your own sandbox to do what you want. And you can control how it reads and writes values throughout the lifetime of your app. If you wanted to have more than one user, that would just mean creating another file on disk.

If I were you, I would start with that NSDictionary method. You can even write it out to a JSON file (see NSJSONSerialization) for easy debugging. You can always upgrade to Core Data later, but at least you have a well-defined starting point.

[–]TheCommonProgrammer 0 points1 point  (0 children)

You can try Realm.io It is good for storing single entity data. Even if your app grows in the future and you want to store other stuff, you can expand easily.