2010-08-09 5 views

답변

18

당신은 dictionaryRepresentation을 통해 볼 수있다.

다음은 유연성을 높이기 위해 NSPredicate을 일반 matcher로 사용하는 구현입니다.

@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 

사용법 :

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

난 당신이 모든 세션

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

을 제거 할 경우 그냥 사용 이에 대한 솔루션을 얻었다는

를 작동합니다
관련 문제