Simple as that, how do I save an Integer for score after the user has restarted the app. I'm trying to use SpriteKit for everything, so keep that in mind. I've tried NSUserDefaults but it doesn't seem to be working.
Asked
Active
Viewed 101 times
0
-
Well it does work so _show_ what you are doing. – matt Mar 15 '14 at 22:09
-
NSUserDefaults is what you should use. Please check your code or post the code that seems to not be working for you. – Tibor Udvari Mar 15 '14 at 22:10
-
You can't "use SpriteKit for everything" because the SpriteKit framework doesn't contain any I/O. NSUserDefaults is the simplest way to go here, and should work. Tell how why and how it doesn't and we can help you. – jemmons Mar 15 '14 at 22:10
-
Googling "ios save data" yields a link like this :http://stackoverflow.com/questions/19197448/how-to-save-data-in-ios – prototypical Mar 15 '14 at 22:20
-
If you are having trouble with NSUserDefaults, then showing your code and any errors would be helpful. But I encourage you to first check out the many questions on this site that already cover this topic. – prototypical Mar 15 '14 at 22:26
1 Answers
1
As msgambel points out below, you can save integers directly into NSUserDefaults via something like:
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"one"];
And separately, if you put an integer into a "NSNumber
" object (i.e. an Objective C object), you can save these in NSUserDefaults or include these objects in arrays or dictionaries.
Check out [NSNumber numberWithInteger:]

Michael Dautermann
- 88,797
- 17
- 166
- 215
-
`[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"one"];` works just fine. – msgambel Mar 15 '14 at 22:53
-