开发者

Is there anything wrong with my NSUserDefaults load operation?

Everything is working as ex开发者_如何学Pythonpected however I just wanted to make sure I am doing this properly:

NSString * uName = [[NSUserDefaults standardUserDefaults]objectForKey:@"key1"];
NSString * pWord = [[NSUserDefaults standardUserDefaults]objectForKey:@"key2"];


you could use the below if you are storing only NSString for key1 and key2.

NSString *myString = [[NSUserDefaults standardUserDefaults] stringForKey:@"keyToLookupString"];

For more read the blog post for using of NSUserDefault.

iPhone Programming Tutorial – Saving/Retrieving Data Using NSUserDefaults


Yup. That's how to read an object from user defaults.

- (NSString *)stringForKey:(NSString *)defaultName will also do the same thing with more static typing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜