A couple of questions regarding the following code:
@implementation NSArray (Find)
- (NSArray *)findAllWhereKeyPath:(NSString *)keyPath equals:(id)value {
NSMutableArray *matches = [NSMutableArray array];
for (id object in self) {
id objectValue = [object valueForKeyPath:keyPath];
if ([objectValue isEqual:value] || objectValue == value) [matches addObject:object];
}
return matches;
}
1- What does (Find) do? I've seen other words like this when doing these implementations, so what exactly is it doing? Is it a keyword, or just for me to know?
2- I got the code from here: http://probablyinteractive.com/2009/2/13/keypaths.html But when I place it on my project and call it
NSArray *filterResults = [allResults findAllWhereKeyPath:@"firstname" equals:firstname];
it returns the warning 'NSArray' may not respond to '-findAllWhereKeyPath:equals:' and if I run it, it crashes. I've placed the code at the beginning of the .m, at the .h and changed it to NSMutableArray, but I keep getting the warning. So, how should I solve this?