내 iPhone 응용 프로그램에서 NSUserDefault
의 모든 목록을 "걷고"특정 항목 만 삭제할 수있는 방법이 있습니까?특정 단어로 시작하는 내 NSUserDefaults를 모두 삭제하십시오.
예를 들어 특정 단어로 시작하는 모든 키 이름을 얻고 싶습니다. 이 같은
뭔가 :
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"Dog*"];
내 iPhone 응용 프로그램에서 NSUserDefault
의 모든 목록을 "걷고"특정 항목 만 삭제할 수있는 방법이 있습니까?특정 단어로 시작하는 내 NSUserDefaults를 모두 삭제하십시오.
예를 들어 특정 단어로 시작하는 모든 키 이름을 얻고 싶습니다. 이 같은
뭔가 :
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"Dog*"];
당신은 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];
난 당신이 모든 세션
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
을 제거 할 경우 그냥 사용 이에 대한 솔루션을 얻었다는
를 작동합니다