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

On Jun 30, 2011, at 11:59 AM, JongAm Park wrote:

> Hello, 
> 
> I wrote a method for NSArray.
> 
> - (NSArray *)objectsForKey:(id)key
> {
>       NSMutableArray *objectsArray = [NSMutableArray arrayWithCapacity:10];
>       
>       for( id item in self )
>       {
>               [objectsArray addObject:[item objectForKey:key]];
>       }
>       
>       return [[objectsArray copy] autorelease];
> }
> 
> What I'm curious is if it is OK to use fast enumeration to implement an 
> NSArray method itself.
> Because the mechanism for fast enumeration is already there, I basically 
> think it will be OK.
> However, wouldn't it better to rely on the most fundamental mechanism like 
> objectAtIndex:?
> I found someone's implementation here at 
> http://svn.opengroupware.org/SOGo/inverse/trunk/SoObjects/SOGo/NSArray+Utilities.m
> Approaching such a way looks reasonable to me, because it should work 
> whatever underlying mechanism is supported by Objective-C.
> 
> Will there be any good/bad aspect in using fast enumeration in this case?
> 
> Thank you.
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/davedelong%40me.com
> 
> This email sent to davedel...@me.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to