• 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
Most efficient way to iterate through an NSArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Most efficient way to iterate through an NSArray


  • Subject: Most efficient way to iterate through an NSArray
  • From: David Avendasora <email@hidden>
  • Date: Mon, 17 Mar 2008 06:41:34 -0400

Hi all,

I find myself often times needing to iterate through an NSArray of EOs. I'm not sure if the way I'm doing it is the most effecient or not. Here's what I normally do:

public void doThisForAllProducts(EOEditingContext ec) {
for (Object aProductObject : products().toArray()) {
Product aProduct = (Product) aProductObject;
aProduct.doThis(ec);
}
}

This is assuming that products() is an NSArray of Product EOs.

Is this a good / the best way to iterate through NSArrays in general? 

I find myself occasionally nesting this loop a couple deep to drill down into several toMany relationships. For example (as a keypath): products.billsOfMaterial.routingSteps.components to get all the components that are possibly used in a product.

On a side note, and the reason for calling products().toArray() is to force EOF to get the real EOs and not just faults. If I just call products() I'll sometimes get EOs, sometimes faults, seemingly by EOF whim. Is that a bug or expected behaviour?

Thanks!

Dave
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Most efficient way to iterate through an NSArray
      • From: Gaastra Dennis - WO Lists <email@hidden>
    • Re: Most efficient way to iterate through an NSArray
      • From: Chuck Hill <email@hidden>
    • Re: Most efficient way to iterate through an NSArray
      • From: Alexander Spohr <email@hidden>
  • Prev by Date: Upgrade to leopard causes ERXBlowfish exception (SOLVED)
  • Next by Date: Re: Most efficient way to iterate through an NSArray
  • Previous by thread: Upgrade to leopard causes ERXBlowfish exception (SOLVED)
  • Next by thread: Re: Most efficient way to iterate through an NSArray
  • Index(es):
    • Date
    • Thread