Reputation: 71
I am developing a game with Spritekit and I'm now at a point where I have to keep track of the user's highscore. There are various different methods for storage with the easiest one being NSUserDefaults, but it's recommend for preferences.
However, I found this Keychain wrapper which tends to save a string with a key:
https://github.com/jrendel/SwiftKeychainWrapper
Do you think it's good to use it? My idea is to convert the score (Integer) to a String before saving it and while retrieving the highscore, I will convert it back from String to Int. Do you think it's a good idea?
Upvotes: 2
Views: 748
Reputation: 8014
The main advantages of the key chain I can see are that entries persists when an app is deleted and can't easily be changed. UserDefaults would be tied to your app Id and lost on app delete: unless you used the global domain.
You could look to use CloudKit key/value storage to achieve cross device high scores, storing the data in the cloud. This would be more work and you would need to add conflict resolution.
Depending on how serious you are taking high scores, you should perhaps consider integrating with Game Center? Ideal if you want high score etc to persist across more than one device.
Upvotes: 1