Strong Like Bull
Strong Like Bull

Reputation: 11297

Is there anything wrong with my NSUserDefaults load operation?

Everything is working as expected however I just wanted to make sure I am doing this properly:

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

Upvotes: 0

Views: 104

Answers (2)

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31722

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

Upvotes: 1

Andrew Pouliot
Andrew Pouliot

Reputation: 5421

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.

Upvotes: 1

Related Questions