ユーザー入力に基づいて、私のNSMutableDictionaryをフィルタリングに取り組んでいる間、私は次のコードを作成しました:NSPredicate predicateWithFormat:(NSString *)inconsistency?
NSString *predicateString = [NSString stringWithFormat:@"SELF beginsWith[cd] %@", searchString];
NSPredicate *pred = [NSPredicate predicateWithFormat:predicateString];
NSArray *filteredKeys = [[myMutableDictionary allKeys] filteredArrayUsingPredicate:pred];
は「searchStringの」この定義にメソッドに渡されます。これは、しかし、が生じ
(NSString*) searchString
次の例外を除いて:
... raise [valueForUndefinedKey:]:このクラスは キーには対応していません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