• 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
Fast enumeration
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fast enumeration


  • Subject: Fast enumeration
  • From: Charlie Dickman <email@hidden>
  • Date: Thu, 22 Jul 2010 15:16:14 -0400

In the past I have used the construct

NSEnumerator *_enumerator = [_array objectEnumerator];
id _id = nil;
while (nil != (_id = [_enumerator nextObject])) {
.
.
.
if (condition)
   break;
}

if (nil == _id) {
.
.
.
}

to determine if the entire contents of _array had been investigated and, if not, which object in _array met the condition.

When trying to use, instead,

for (id _id in _array) {
}

how, without reverting to effectively using an enumerator as in

id theID = nil;
for (id _id in _array) {
.
.
.
if (condition) {
   theID = _id;
   break;
}
.
.
.
if (nil != theID) {
.
.
.
}

does one accomplish the same thing?

Charlie Dickman
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: Fast enumeration
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: print object by %@ [solved]
  • Next by Date: Re: Array controllers in code?
  • Previous by thread: Re: print object by %@ [solved]
  • Next by thread: Re: Fast enumeration
  • Index(es):
    • Date
    • Thread