Reputation: 478
I'm storing all my data in NSUserDefaults. Now I'm trying to store some keys with a specific prefix in an Array. Therefore, I first load the UserDefaults in a Dictionary.
NSString *myPrefix = @"prefix";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *dict = [defaults dictionaryRepresentation];
for (NSString *keyWithPrefix in dict.keyEnumerator) {
if ([keyWithPrefix hasPrefix: myPrefix]) {
[relevantKeys addObject: keyWithPrefix];
}
}
The Problem is: when I print "dict" (which represents UserDefaults). There are some keys missing. Does NSUserDefaults delete keys, that are not needed temporarily?
Upvotes: 1
Views: 488
Reputation: 5314
You should probably be using -synchronize
method when storing what you want. i,e:
[[NSUserDefaults standardUserDefaults] setValue:someDictionary forKey:@"someKey"];
[[NSUSerDefaults standardUserDefaults] synchronize];
Upvotes: 0
Reputation: 21221
Nope it does not, NSUserDefault is a persistance storage, Please read the following answer it has a very good explanation How persistent is [NSUserDefaults standardUserDefaults]?
Upvotes: 1
Reputation: 14677
No, but are you calling [NSUserdefaults synchronize]
when you are updating them ?
Upvotes: 0