Re: fast enumeration
Re: fast enumeration
- Subject: Re: fast enumeration
- From: Boyd Collier <email@hidden>
- Date: Sat, 27 Apr 2013 14:20:08 -0700
Excellent! Thanks very much for pointing this out.
Boyd
On Apr 27, 2013, at 11:21 AM, Jens Alfke wrote:
>
> On Apr 27, 2013, at 11:11 AM, Boyd Collier <email@hidden> wrote:
>
>> NSEnumerator *myEnumerator = [arrayOfLabels objectEnumerator];
>> NSString *aString = [myEnumerator nextObject]; // gets us past the first element
>> NSLog(@"the label is %@", aString); // just to check; doesn't get used
>>
>> NSArray *arrayOfLabels = [myEnumerator allObjects];
>>
>> for (aString in arrayOfLabels) {
>> // these are the strings that I'm interested in and will use
>> NSLog(@"the label from enumeration is %@", aString);
>> }
>
> You don't need to create a separate array, since NSEnumerator already supports fast-enumeration.
>
> NSEnumerator *myEnumerator = [arrayOfLabels objectEnumerator];
> (void)[myEnumerator nextObject]; // gets us past the first element
> for (aString in myEnumerator) {
> ...
> }
>
> —Jens
_______________________________________________
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