我有
NSDictionary *myDictionary = @{ @"1":@"Egg Benedict",
@"2":@"Mushroom Risotto",
@"3":@"Full Breakfast",
@"4":@"Hamburger",
@"5":@"Ham and Egg Sandwich",
@"6":@"Cream Brelee"};
NSMutableArray *myKeys = [NSMutableArray arrayWithArray:[myDictionary allKeys]];
我想用谓词过滤 myDictionary 。我应该如何构建它?作为一种算法,我想它应该是这样的:
[filteredKeys removeAllObjects];
for (NSString *a in myKeys) {
if ([[myDictionary objectForKey:a] rangeOfString:searchText].location != NSNotFound) {
[filteredKeys addObject:a];
}
}
我怎样才能用谓词字符串来实现呢?