开发者

Best way to store a string in an iPhone app?

开发者 https://www.devze.com 2022-12-23 20:05 出处:网络
I\'ve started a new iPhone app that needs to remember a single, 40-char string. That\'s it. I\'vehooked into Core Data, and am reading about it now, but it really s开发者_如何学Goeems like overkill. I

I've started a new iPhone app that needs to remember a single, 40-char string. That's it. I've hooked into Core Data, and am reading about it now, but it really s开发者_如何学Goeems like overkill. Is there an easier way to do something so simple?


NSUserDefaults would probably be the easiest way

// To Save
[[NSUserDefaults standardUserDefaults] setString:myString forKey:kMyStringKey];

//To Load
NSString * myString = [[NSUserDefaults standardUserDefaults] stringForKey:kMyStringKey];

This will persistence between sessions.

Edit: This is assuming of course that the string is not constant for everyone using the program. If it is you can just hard code it. This is for if every instance of the app needs a different string, but you want the string saved between runs of the app.

0

精彩评论

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

关注公众号