This tutorial will show you how to save an integer to your iphone.
Start by downloading the SaveCount Code.
The first bit of code that is very important is in the SaveCountAppDelegate.m file.
NSDictionary *appDefaults = [NSDictionary
This code is run when your app is first installed on an iphone or ipod touch, the code creates an NSNumber called count that is initialized to 0.
In MainMenu.m, If you run the code you will see a menu with a new game, load game, help, and exit buttons. When you click the new game button the following code will run.
SaveCountAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
The first line sets the Count that we initialized back to 0, so that any time you click on the new game button Count starts over.
Then we call the delegate and run its’ function nextLevel.
Now the last line of interest is in the HelloWorldScene.m file, in the reset function.
This line sets the count integer, that is defined in the HelloWorldScene.h file, to what ever integer is in Count, and that is all there is to saving.
If you have any questions feel free to comment.
Copy right Britney Lee Johnson October 2010.