I'm making a game app, and I want to save scores for each stage.
There seems to be a lot of options like the following, but I would like to use NSUserDefaults if possible.
·NSUserDefaults
·CoreData
·Parse
I thought about saving the array element number (someArray[0]
) for each stage as follows:
But there seems to be a better way.
I would appreciate it if you could give me some advice.
varsomeArray: Int!
varscore = 0
let userDefaults=NSUserDefaults.standardUserDefaults()
// Replace array elements as many stages as possible
someArray = [0,0,0,0,0]
someArray[0] = score
userDefaults.setObject(someArray, forKey: "someArray")
userDefaults.synchronize()
someArray=userDefaults.objectForKey("someArray") as! [Int]
If you put it in NSUserDefaults instead of int array, but NSDictionary array, you can save other parameters for each stage, so it will be convenient.
someArray=[
["score":0, "time":100],
["score":0, "time":100],
]
someArray[0]["score"]=score
userDefaults.setObject(someArray, forKey: "someArray")
userDefaults.synchronize()
someArray=userDefaults.objectForKey("someArray") as!Array
If you use CoreData, SQLite, etc., you can sort easily, so you can make a ranking. (It may take some time to set it up...)
With Parse, I think I can make an internet ranking. (Parse will be finished, so if you want to make a new one now, would it be Firebase?)
606 Uncaught (inpromise) Error on Electron: An object could not be cloned
567 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
572 Understanding How to Configure Google API Key
567 Who developed the "avformat-59.dll" that comes with FFmpeg?
885 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.