开发者

iPhone: How can I store a high score to disk

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜