Searching array with block
Searching array with block
- Subject: Searching array with block
- From: Erik Stainsby <email@hidden>
- Date: Sun, 11 Nov 2012 14:30:48 -0800
Following an example from Stephan Kochan's book I concocted the following method, which alas does not work:
- (IBAction) updateIncrementalSearch:(id)sender {
NSString * term = [sender stringValue];
if(term) {
NSMutableArray * matchResults = [NSMutableArray new];
NSUInteger index = [[self content] indexOfObjectPassingTest:^(RSPerson * rsp, NSUInteger idx, BOOL *stop) {
if([[rsp firstName] caseInsensitiveCompare:term] == NSOrderedSame) {
// *stop = YES;
[matchResults addObject:rsp];
return YES;
}
else {
return NO;
}
}];
#pragma unused(index)
if([matchResults count]){
self.matches = [NSArray arrayWithArray:matchResults];
// throw a notification
}
else {
NSLog(@" [d] %s %@",__LINE__,__PRETTY_FUNCTION__, @"no match found");
}
for(RSPerson * p in self.matches) {
NSLog(@" [d] %s %@",__LINE__,__PRETTY_FUNCTION__, p.firstName);
}
}
}
This consistently reports
2012-11-11 14:20:14.050 SearchController[30109:303] [0105] -[RSSearchController updateIncrementalSearch:] (null)
in spite of having 51 records which have firstName values… And regardless of the number of matches which it ought to be generating it returns exactly one result each time. (And btw, is it legit to NSLog() from inside a block ?)
What have I missed ? Anyone ?
TIA,
Erik
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden