Does anyone know how to use key-paths in NSPredicate?
I’m trying to use key-paths, but an error occurred.
I want to use "dictate like 'AAA'" as key-path.
Source code:
- (void)Predictate{
dictate = [[NSMutableArray alloc]initWithObjects:@"AAA",@"BBB",@"CCC", nil];
NSPredicate *test = [NSPredicate predicateWithFormat:@"dictate like 'AAA'"];
NSMutableArray *result = [dictate filteredArrayUsingPredicate:test];
NSLog(@"%@",result);
}
This is the error message:
2012-01-02 01:33:33.673 filter[1867:707] * Terminating app due to
uncaught exception ‘NSUnknownKeyException’, reason:
‘[<__NSCFConstantString 0x1000022f0> valueForUndefinedKey:]: this
class is not key value coding-compliant for the key dictate.’
“self LIKE ‘AAA'” works. Tested.
It’s kind of subtle fact that you can send
selfto Objective-C object and get the pointer to the object itself (try[obj performselector:@selector(self)]). So that’s how it works.