虽然基于用户输入过滤我的NSMutableDictionary工作,我创建了下面的代码:NSPredicate predicateWithFormat:(NSString *)不一致?
NSString *predicateString = [NSString stringWithFormat:@"SELF beginsWith[cd] %@", searchString];
NSPredicate *pred = [NSPredicate predicateWithFormat:predicateString];
NSArray *filteredKeys = [[myMutableDictionary allKeys] filteredArrayUsingPredicate:pred];
“搜索字符串”传递到这个定义的方法:
(NSString*) searchString
然而,这导致以下例外情况如下:
... raise [valueForUndefinedKey:]:该类别为 对于ke不符合密钥值Y ...
的修复竟然是:
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF beginsWith[cd] %@", searchString];
NSArray *filteredKeys = [[myMutableDictionary allKeys] filteredArrayUsingPredicate:pred];
我不明白,这就是为什么后者的工作,和前抛出异常。我已阅读key value coding一点点,但我不明白它在这里如何适用。 (即只是通过改变NSPredicate的定义)有人能够启发我吗?
更新: 为了回应jtbandes评论,我继续创建了一个TestApp项目来演示此问题。 http://dl.dropbox.com/u/401317/TestApp1.tar.gz
如果你希望我们弄清楚它的含义,你将不得不向我们展示整个异常。 – jtbandes