开发者

storing preferences within the app to be used later

开发者 https://www.devze.com 2023-01-06 17:06 出处:网络
How can I store a large float value, like 0.00032012 in the app?? I need to store that number, so when someone click a save preferences button, it stores a variable. Then when I relaunc开发者_StackOve

How can I store a large float value, like 0.00032012 in the app?? I need to store that number, so when someone click a save preferences button, it stores a variable. Then when I relaunc开发者_StackOverflow社区h the app, it will remember that number and post it in a text field.

I was thinking of using plist, but how can I store variables in the plist??? Examples?

Any ideas???


Take a look at NSUserDefaults and the user defaults guide:

NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
// save:
[defs setDouble:0.0032 forKey:@"myNumber"];
// load:
double d = [defs doubleForKey:@"myNumber"];


UserDefaults is the best way to store preferences like this. You can store Cocoa's built-in NSNumber objects by default, or you can use NSData if you need more storage space.

0

精彩评论

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