Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chen8002004

macrumors newbie
Original poster
May 22, 2011
26
0
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
 
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.