开发者

Is there anything wrong with my NSUserDefaults load operation?

开发者 https://www.devze.com 2023-03-06 08:08 出处:网络
Everything is working as ex开发者_如何学Pythonpected however I just wanted to make sure I am doing this properly:

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

精彩评论

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

关注公众号