views:

32

answers:

2

How would I access the properties of an object stored in an array?

something like:

[myArray objectAtIndex:0].intProperty = 12345;
+3  A: 

You need to cast the object first.

((MyObjectType *) [myArray objectAtIndex:0]).intProperty = 12345;

Jacob Relkin
A: 

First, you will need to store the ID in a variable, like

(id) myObject = [myArray objectAtIndex:0];

Then you can manipulate it:

myObject.intProperty = 12345;

And store it again:

[myArray removeObjectAtIndex:0]; // Remove it before setting it again
[myArray insertObject:myObject atIndex:0];

EDIT: Or you could use Jacob's way, which is much better :)

Emil