Mahesh Babu
Mahesh Babu

Reputation: 3433

How to edit stored value in NSUserDefaults

I am storing some string value in NSUserDefaults,

In the next button click I need to edit stored value and save new string in the place of old string.

How can I do this.

Can any one please help me.

Thank you in advance.

Upvotes: 4

Views: 4817

Answers (2)

GhostRider
GhostRider

Reputation: 1207

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

// getting an NSString

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"Password"]; 

[prefs setObject:@"" forKey:@"Password"];

NSString  *passwordStr = [prefs stringForKey:@"Password"];

[[NSUserDefaults standardUserDefaults] synchronize];

Upvotes: 5

Costique
Costique

Reputation: 23722

[[NSUserDefaults standardUserDefaults] setObject: newStringValue forKey: kMyKey];

Upvotes: 9

Related Questions