smudo78
smudo78

Reputation: 478

Does NSUserDefaults delete keys, that are not needed temporarily?

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

Answers (3)

skram
skram

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

Omar Abdelhafith
Omar Abdelhafith

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

Lefteris
Lefteris

Reputation: 14677

No, but are you calling [NSUserdefaults synchronize] when you are updating them ?

Upvotes: 0

Related Questions