NSUserdefault

hii NSUserDefault is the default class provided to store some information by default. The storage is permanent storage  but stores a very little content as a dictionary. It uses a key value pairing concept.

 

the sample code to store the data in NSUserdefaults is

 

-(IBAction)savetouserdefaults:(id)sender

{

    

    

    

    NSUserDefaults *defaultsstorage=[NSUserDefaults standardUserDefaults];

//text1.text is the my textfiled1 data    

    [defaultsstorage setObject:text1.text forKey:@”name”];

    [defaultsstorage setObject:text2.text forKey:@”lastname”];

    

    [defaultsstorage synchronize];

    

 

}

 

 

// to retrieve the data from nsuserdegfaults

 

 

prints the associated data with the keys

 NSUserDefaults *defauls=[NSUserDefaults standardUserDefaults];

    

    NSLog(@”%@”,[defauls objectForKey:@”name”]);

    NSLog(@” lastname %@”,[defauls objectForKey:@”lastname”]);

 

 

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