NSMutableArray help

Apprentice
Posts: 5
Joined: 2012.04
Post: #1
Hello everyone I a bit new to iOS programming so here goes.

I have a class called sceneObjects and from that I have a few subclasses "Ants" and "Food". All of these are stored in a NSMutableArray of sceneObjects. The problem is that Ants need to know the location of Food so how do I access the right elements and give them other elements information within the same array.

Thank you for your time.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #2
create 2 more arrays called antObjects and foodObjects and stick ants and foods into each respectively.

The cost storage of doing so is negligible, and now you can easily iterate through them.

The slow way would be to iterate over each sceneObject and test the type (or have the class store some "type" you can query on)
Quote this message in a reply
⌘-R in Chief
Posts: 1,247
Joined: 2002.05
Post: #3
*ahem* SceneObject, not sceneObject, please. Stick to Obj-C conventions when using Obj-C. Smile

Other than that, ditto to skyhawk.
Quote this message in a reply
Apprentice
Posts: 5
Joined: 2012.04
Post: #4
Thanks skyhawk that sounds like just what I need to do. Grin
Quote this message in a reply
Post Reply