Re: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?
Re: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?
- Subject: Re: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?
- From: JongAm Park <email@hidden>
- Date: Thu, 30 Jun 2011 13:51:54 -0700
Um... Thanks for your reply.
The last time I used that was about 5 or 6 years ago, and I wondered yesterday where it went away. :)
Thanks for pointing out that method.
BTW, my actual question was if it is meant to use fast enumeration in a collection class implementation.
Although I tried to add objectsForKey: to existing NSArray, it should be OK, because it is to rely on existing, fully functional one.
However, let's say we write a class like NSArray that supports fast enumeration, block based enumeration, numerator based enumeration and finally index based iteration.
The rationale behind "enumerator" pattern is to unify the way to access collection classes no matter what they actually look like.
So, enumerator pattern is actually written in index based iteration wrapped with enumerator pattern.
Similarly, I guessed fast enumeration was based on either index iteration or enumerator pattern.
Also, fast enumeration is a language feature. So, if Objective-C without fast enumerator is used, methods written with fast enumerator would not work.
So, my question was originally for that. :)
Anyway, it's not big deal now.
Thank you :)
JongAm Park
On Jun 30, 2011, at 12:02 PM, Dave DeLong wrote:
> Yeah, that should be fine, but it's unnecessary.
>
> You can just do:
>
> NSArray *objectsArray = [theArray valueForKey:key];
>
> And it'll do pretty much the same thing (except that it'll call -valueForKey: on each item in the array, and not objectForKey:. However, if the objects are NSDictionaries, that's pretty much the same thing).
>
> Dave
_______________________________________________
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