how to share an item between interfaces

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

  1. chen8002004 macrumors newbie

    Joined:
    May 22, 2011
    #1
    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?
    Definition:
    Code:
    @interface A: NSObject
    { NSString *commonMember;}
    @property (nonatomic, copy) NSString *commonMember;
    @end
    @interface B: NSObject
    { NSString *commonMember;}
    @property (nonatomic, copy) NSString *commonMember;
    @end
    Use:
    Code:
    A* aa=[[A alloc] init];
    B* bb=[[B alloc] init];
    bb.commonMember=aa.commonMember;
    // the value from one of the interfaces changed:
    bb.commonMember=@"new value";
    // aa.commonMember is not updated automatically
     
  2. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    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

    Joined:
    Apr 22, 2005
    #3
    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