Created
July 7, 2012 06:18
-
-
Save kevinlawler/3065038 to your computer and use it in GitHub Desktop.
Using KVO with NSSingleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
@end | |
#import "Bank.h" | |
@implementation Bank | |
@synthesize accountBalance; | |
@end | |
#import "NSSingleton.h" | |
@interface Person : NSSingleton | |
@end | |
#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]); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment