how to share an item between interfaces

Discussion in 'iOS Programming' started by chen8002004, Aug 30, 2011.

  1. chen8002004 macrumors newbie

    May 22, 2011
    I would like to share a member between interfaces. If the member changed in an interface, the member from other interfaces should be changed automatically. How could I do this?
    @interface A: NSObject
    { NSString *commonMember;}
    @property (nonatomic, copy) NSString *commonMember;
    @interface B: NSObject
    { NSString *commonMember;}
    @property (nonatomic, copy) NSString *commonMember;
    A* aa=[[A alloc] init];
    B* bb=[[B alloc] init];
    // the value from one of the interfaces changed:
    bb.commonMember=@"new value";
    // aa.commonMember is not updated automatically
  2. jnoxx macrumors 65816


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    Look for SynthesizedSingleton..
    Make a shared model for your strings, then just import it into your code, set the string, if it's changed, the other methods will pick it up, since they are reading the same singleton class.
  3. admanimal macrumors 68040

    Apr 22, 2005
    Could you describe what sort of data you are storing in this variable, as well as how many classes/variables like this you will need, in more detail? This seems like an unusual thing to do and I wonder if there isn't a better pattern to follow to achieve the same effect.

Share This Page