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?
Try saving the integer in NSUserDefaults.
There is an example of someone storing an integer in there here.
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.
精彩评论