Reputation: 38213
I have a int which is my high score:
NSInteger highScore;
I want to store it persistently to disk
Do I have to convert it to a string, then write the string to a file, then parse it back when I want to read it. Or is there a better way to store small amounts of data?
Upvotes: 0
Views: 274
Reputation: 44
You can write the NSInteger to a file withougt converting it to a string like so:
NSInteger foo = 134;
fwrite(&foo, sizeof(NSInteger),1, filePointer);
Then you can just read it back again using fread the same way.
Upvotes: 0
Reputation: 37761
Try saving the integer in NSUserDefaults.
There is an example of someone storing an integer in there here.
Upvotes: 3