2010-08-09 9 views

Antwort

18

Sie durch die dictionaryRepresentation aussehen kann.

Hier ist eine Implementierung, die NSPredicate als generische Matcher für größere Flexibilität verwendet.

@interface NSUserDefaults (JRAdditions) 
- (void)removeObjectsWithKeysMatchingPredicate:(NSPredicate *)predicate; 
@end 

@implementation NSUserDefaults (JRAdditions) 

- (void)removeObjectsWithKeysMatchingPredicate:(NSPredicate *)predicate { 
    NSArray *keys = [[self dictionaryRepresentation] allKeys]; 
    for(NSString *key in keys) { 
     if([predicate evaluateWithObject:key]) { 
     [self removeObjectForKey:key]; 
     } 
    } 
} 

@end 

Verbrauch:

NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH %@", @"something"]; 
[[NSUserDefaults standardUserDefaults] removeObjectsWithKeysMatchingPredicate:pred]; 
0

i für diese Got Lösung es nur verwenden, wenn Sie alle Sitzungen entfernen möchten

NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier]; 
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain]; 

es funktioniert

Verwandte Themen