How to have a reference to the data

Discussion in 'iOS Programming' started by chen8002004, Jun 14, 2011.

  1. chen8002004, Jun 14, 2011
    Last edited: Jun 16, 2011

    macrumors newbie

    Joined:
    May 22, 2011
    #1
    I would like to have a seperate class holding the data. Two objects can read and update the data. Is it possible to have one object own the data and the other object hold a pointer to the data? The other object will not retain the data class. Will this solution cause any possible memory leak?
     
  2. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    U could hold a singleton, and put the date in there :)
    (look for SynthesizeSingleton.h)
     
  3. macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #3
    A singleton might be overkill if you really just have the three objects.

    You could have object A create and own object C, and then set an ivar in object B to equal the ivar in object A that points to object C. Just don't release object C from object B, unless you retain it there too.
     
  4. thread starter macrumors newbie

    Joined:
    May 22, 2011
    #4
    I did what xStep told me to. These is no error when running, but I get some warnings in Build: “No ‘assign’, ‘retain’, or ‘copy' attribute is specified - ‘assign’ is assumed” and “Assign attribute (default) not appropriate for non-gc object property ‘iC’ “. Can anyone help me with this warning?
    Code:
    @interface B: NSObject{
    C* iC;
    }
    @property C* iC;
    @end
     
  5. xStep, Jun 16, 2011
    Last edited: Jun 16, 2011

    macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #5
    Typically for your property statement you'd define at least whether it will perform a copy, a retain of the object id or simple accept an assignment of the id value. I'll leave it to you to learn more.

    To remove the warnings, at minimum your code would look something like this;

    Code:
    @property (retain) C* iC;
    
    or

    Code:
    @property (assign) C* iC;
    
     

Share This Page