Вы можете просмотреть dictionaryRepresentation
.
Вот реализация, которая использует NSPredicate
в качестве универсального сопоставителя для большей гибкости.
@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];