2010-08-09 11 views

risposta

18

È possibile guardare attraverso il dictionaryRepresentation.

Ecco un'implementazione che utilizza NSPredicate come un generico per una maggiore flessibilità.

@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 

Usage:

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

ho ricevuto soluzione per questo basta usarlo in cui si desidera rimuovere tutte le sessioni

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

che funzionerà

Problemi correlati