accessing an array outside my class

Discussion in 'iOS Programming' started by ulquiorra, Jun 17, 2009.

  1. ulquiorra macrumors member

    Joined:
    Jun 17, 2009
    #1
    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.
    Code:
    [ 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.
     
  2. namanhams macrumors regular

    Joined:
    Jun 3, 2009
    #2
    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.
     
  3. ulquiorra thread starter macrumors member

    Joined:
    Jun 17, 2009
    #3
    thnx , I made a function that can do it , but thank you for your reply;)
     

Share This Page