Re: Searching array with block
Re: Searching array with block
- Subject: Re: Searching array with block
- From: Fritz Anderson <email@hidden>
- Date: Sun, 11 Nov 2012 17:05:14 -0600
On 11 Nov 2012, at 4:30 PM, Erik Stainsby <email@hidden> wrote:
> 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.
The array is built up as a side effect of -[NSArray indexOfObjectPassingTest:]. The block that implements the test returns YES when the firstName matches.
Reflect that a method that searches for the index (singular) of a member of an array will stop searching when it finds the object. (Why is it always in the last place you look?) That is, it stops as soon as you return YES, upon the first match.
Your example doesn't use the index indexOfObjectPassingTest: returns. Why do you not want to use -enumerateObjectsUsinghBlock:?
Or, you could use index_es_OfObject_s_PassingTest: and objectsAtIndexes:.
> (And btw, is it legit to NSLog() from inside a block ?)
Yes.
— F
_______________________________________________
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