I have about four classes let us assume A,B,C and D ,Now my classes B,C,D need to observe the value of class A and get notified when the value changes. I have observed the value in class B and I am not able to get notified in the other two classes say C and D. thanks in advance..
- (void)viewDidLoad
{
[super viewDidLoad];
newClassAToBeObserved=[[ClassATobeObserved alloc]init];
[newClassAToBeObserved addObserver:self forKeyPath:@"StatusToken" options:NSKeyValueObservingOptionNew context:NULL];
ClassB*classB=[[ClassB alloc]init];
[classB func];
ClassC*classc=[[ClassC alloc]init];
[classc func];
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"StatusToken"])
{
NSLog(@"changed value is : %@",[object valueForKeyPath:keyPath]);
}
}
-(IBAction)ClickIt
{
[newClassAToBeObserved setStatusToken:@"TokenExpired"];
NSLog(@"Value-->%@",newClassAToBeObserved.StatusToken);
}