Iphone 删除所有以某个单词开头的默认值
有没有办法让我“浏览”iPhone应用程序中所有Iphone 删除所有以某个单词开头的默认值,iphone,ios,objective-c,xcode,nsuserdefaults,Iphone,Ios,Objective C,Xcode,Nsuserdefaults,有没有办法让我“浏览”iPhone应用程序中所有NSUserDefaults的列表,只删除某些 例如,我想得到所有以某个单词开头的关键字名称 大概是这样的: [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"Dog*"]; 你可以透过窗户看 这里有一个实现,它用作通用匹配器,以获得更大的灵活性 @interface NSUserDefaults (JRAdditions) - (void)removeObjectsWithK
NSUserDefault
s的列表,只删除某些
例如,我想得到所有以某个单词开头的关键字名称
大概是这样的:
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"Dog*"];
你可以透过窗户看
这里有一个实现,它用作通用匹配器,以获得更大的灵活性
@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];
它会起作用的