Tuesday 25 September 2012

NSUser Defaults


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"]);


No comments:

Post a Comment