1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

How to have a reference to the data

Discussion in 'iPhone/iPad Programming' started by chen8002004, Jun 14, 2011.

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

    macrumors newbie

    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


    U could hold a singleton, and put the date in there :)
    (look for SynthesizeSingleton.h)
  3. macrumors 68000

    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. macrumors newbie

    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?
    @interface B: NSObject{
    C* iC;
    @property C* iC;
  5. xStep, Jun 16, 2011
    Last edited: Jun 16, 2011

    macrumors 68000

    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;

    @property (retain) C* iC;

    @property (assign) C* iC;

Share This Page