fast enumeration
fast enumeration
- Subject: fast enumeration
- From: Boyd Collier <email@hidden>
- Date: Sat, 27 Apr 2013 11:11:56 -0700
I have an array of NSStrings that in some circumstances, I'd like to go through using fast enumeration starting with the second element in the array. After a bit of fooling around, I came up with the following, which seems to work:
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);
}
But I worry that in my inexperience with fast enumeration I may have committed a sin that is likely to bite me later, or that what I've done is really less effective than using an old-fashioned loop. Perhaps some of you have run bench-marks or come up with a more elegant way of doing this sort of thing.
Many thanks for your insights,
Boyd
_______________________________________________
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