Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Using KVO with NSSingleton
Bank *b = [Bank instance];
Person *p = [Person instance];
[b addObserver:p forKeyPath:@"accountBalance" options:NSKeyValueObservingOptionNew context:NULL];
b.accountBalance = [NSNumber numberWithInt:99];
#import "NSSingleton.h"
@interface Bank : NSSingleton
@property (nonatomic, strong) NSNumber *accountBalance;
#import "Bank.h"
@implementation Bank
@synthesize accountBalance;
#import "NSSingleton.h"
@interface Person : NSSingleton
#import "Person.h"
@implementation Person
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
NSLog(@"keypath: %@", keyPath);
NSLog(@"object: %@", [object description]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment