Vig*_*abu 5 iphone full-text-search objective-c nsmutabledictionary ios
HI,我有一个NSMutableDicitionary包含小写和大写的键.所以目前我不知道如何使用目标c找到字典中的密钥而不管密钥.
救援类别.好的,所以这是一个老帖子......
@interface NSDictionary (caseINsensitive)
-(id) objectForCaseInsensitiveKey:(id)aKey;
@end
@interface NSMutableDictionary (caseINsensitive)
-(void) setObject:(id) obj forCaseInsensitiveKey:(id)aKey ;
@end
@implementation NSDictionary (caseINsensitive)
-(id) objectForCaseInsensitiveKey:(id)aKey {
for (NSString *key in self.allKeys) {
if ([key compare:aKey options:NSCaseInsensitiveSearch] == NSOrderedSame) {
return [self objectForKey:key];
}
}
return nil;
}
@end
@implementation NSMutableDictionary (caseINsensitive)
-(void) setObject:(id) obj forCaseInsensitiveKey:(id)aKey {
for (NSString *key in self.allKeys) {
if ([key compare:aKey options:NSCaseInsensitiveSearch] == NSOrderedSame) {
[self setObject:obj forKey:key];
return;
}
}
[self setObject:obj forKey:aKey];
}
@end
Run Code Online (Sandbox Code Playgroud)
请享用.
| 归档时间: |
|
| 查看次数: |
3018 次 |
| 最近记录: |