PDA

View Full Version : accessing an array outside my class




ulquiorra
Jun 17, 2009, 09:01 AM
Hello everyone , I'm still new to iPhone programming and objective c so bear with me.
I would like to access my array from one to another class.
How can I realize this.
This is my situation :

I'm reading an xml file and my parser saves a lot in an array. I would like to assign the values from this array to an object.

ex.

[ aLabel setTitle: myarray objectAtIndex:2] forState:UIControlStateNormal];


myarray would be the array in my parserclass.

Does anyone know how to do this( or perhaps know an easier way ) ?
Again i'm new so if someone offers an explanation a little code sample would be nice:D
thanks in advance.



namanhams
Jun 18, 2009, 11:25 PM
Hi,

I'm not sure i understand your issue, but here's something that may help :

Let say you have class A and class B, class A wants to access the array of class B.

First thing, class B must provide some ways for the outside world to access its array. You can do it in 2 ways :
- define a property :

@interface B {
......
NSArray *myArray;
}
@property NSArray *myArray;
......

@implementation B
@synthesize myArray;

- provide a method to return myArray.


Second thing, A must have reference to B.


Hope this helps.

ulquiorra
Jun 19, 2009, 05:18 AM
thnx , I made a function that can do it , but thank you for your reply;)