views:

34

answers:

1
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"Dog*"];

Is there a way for me to "walk" through a list of all the userDefault values in my iPhone app, and only delete certain ones?

I.E. All the keyNames that start with a certain word.

+3  A: 

You can look through the dictionaryRepresentation.

A quick untested example:

- (void) removeEntriesStartingWithString:(NSString *) string {
   NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
   NSArray *keys = [[[defaults dictionaryRepresentation] allKeys] copy];
   for(NSString *key in keys) {
       if([key hasPrefix:string]) {
          [defaults removeObjectForKey:key];
       }
   }
   [keys release];
}
Jacob Relkin