आप 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];
स्रोत
2010-08-09 01:32:12