• 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
Re: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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: Dave DeLong <email@hidden>
  • Date: Thu, 30 Jun 2011 12:02:18 -0700

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 (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

_______________________________________________

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: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?
      • From: JongAm Park <email@hidden>
References: 
 >[Q] Will the be any problem in implementing an NSArray method using fast enumeration? (From: JongAm Park <email@hidden>)

  • Prev by Date: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?
  • Next by Date: Re: dealloc and scarce resources
  • Previous by thread: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?
  • Next by thread: Re: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?
  • Index(es):
    • Date
    • Thread