Created
April 29, 2012 23:35
-
-
Save tatey/2554031 to your computer and use it in GitHub Desktop.
With and without branching
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
| @implementation Test1 | |
| - (id)init { | |
| self = [super init]; | |
| if (self) { | |
| [self addObserver:self forKeyPath:@"property1" options:0 context:NULL]; | |
| [self addObserver:self forKeyPath:@"property2" options:0 context:NULL]; | |
| } | |
| } | |
| - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { | |
| if ([keyPath isEqualToString:@"property1"]) { | |
| // Do something. | |
| } else if ([keyPath isEqualToString:@"property2"]) { | |
| // Do something. | |
| } | |
| } | |
| @end |
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
| @implementation Test2 | |
| - (id)init { | |
| self = [super init]; | |
| if (self) { | |
| [self addObserver:self forKeyPath:@"property1" options:0 context:@selector(property1DidChange:)]; | |
| [self addObserver:self forKeyPath:@"property2" options:0 context:@selector(property2DidChange:)]; | |
| } | |
| return self; | |
| } | |
| - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { | |
| [self performSelector:(SEL)context withObject:change]; | |
| } | |
| - (void)property1DidChange:(NSObject *)change { | |
| // Do something. | |
| } | |
| - (void)property2DidChange:(NSObject *)change { | |
| // Do something. | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment