Read and Write with NSUserDefault

Hello Friends , here going to put code for read and write with NSUserDefaults for my beginner Friends 🙂

NSUserDefaults stores data in dictionary format , you can set value for key and retrive that value through same key.

Code for Set Value in NSUserDefault :

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

[defaults setObject:@”deval Chauhan” forKey:@”Username”];

[defaults setObject:@”developer” forKey:@”Password”];

 

Code to Retrive value from NSUserDefault :

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

NSString *username = [defaults objectForKey:@”Username”];

NSString *Password = [defaults objectForKey:@”Password”];

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s