How to Saving/Retrieving Data using- NSUserDefaults :iPhone ( like a session) | Coding Cluster - using asp.net, c#, mvc 4, iphone, php, ios, javascript, in asp.net mvc 3 & more
 

How to Saving/Retrieving Data using- NSUserDefaults :iPhone ( like a session)

Wednesday

Save and retrieve data by using NSUserDefaults - iPhone:
We can save and retrieve different types of data using the NSUserDefaults object.  Saving this way is great for when you want to save small amounts of data such as userName,IDs,Date,Time and program state. You can call NSUserDefaults from anywhere in your app.

Simply it's work like  a session in iphone.

Saving different types of data using the NSUserDefaults in iphone

NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];

// saving an NSString value
[userDefault setObject:@"YourTextHere" forKey:@"key_String_Identifier"];

// saving an NSInteger value
[userDefault setInteger:99 forKey:@"Key_Integer_Identifier"];

// saving a Double value
[userDefault setDouble:10.8 forKey:@"Key_double_Identifier"];

// saving a Float value
[userDefault setFloat:1.99 forKey:@"Key_float_Identifier"];

//Don't forget to synchronize the data you set after you're done.
[userDefault synchronize];

Retrieving data using the NSUserDefaults in iphone

NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];

// getting an NSString value
NSString *udString = [userDefault stringForKey:@"key_String_Identifier"];
//and you get, udString = YourTextHere;

// getting an NSInteger value
NSInteger udInt = [userDefault integerForKey:@"Key_Integer_Identifier"];
//and you get, udInt  = 99;

// getting an Double value
double udDouble = [userDefault doubleForKey:@"Key_double_Identifier"];
//and you get, udDouble = 10.8;

// getting an Float value
float udFloat = [userDefault floatForKey:@"Key_float_Identifier"];
//and you get, udFloat  = 1.99;


0 comments:

Post a Comment

Share your thoughts here...

 
 
 

RECENT POSTS

Boost

 
Blogger Widgets