• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Searching array with block
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Searching array with block
      • From: Fritz Anderson <email@hidden>
    • Re: Searching array with block
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Display alert sheet when application is not active
  • Next by Date: Re: Searching array with block
  • Previous by thread: Re: Core Data fetch performance
  • Next by thread: Re: Searching array with block
  • Index(es):
    • Date
    • Thread