I have like 100 levels in my game and I want, for example, to store completion rate (in %) and highscore (int)
What would be the best way to accomplish it with NSUserDefaults?
Should I use individual keys for that like
"levelCompletion%number%", "levelHighscore%number%"
or maybe store a collection somehow
"levelInfo%number%"
And an object for levelInfo key would be NSDictionary, for example.
Which way is more efficient?
I would make a dictionary with all of the keys for each level, and nothing/empty/NSNumber(0) values. That way when the defaults are spooled out, all 100 will be there for examination, although normally most would be "0".
There is no efficiency concern here, this is a triviality in storage terms and should be at the bottom of any list of premature optimization!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.