Created
August 21, 2014 10:09
-
-
Save jdelStrother/cb138903fce203704261 to your computer and use it in GitHub Desktop.
This file contains 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
@interface Person : NSObject | |
@property NSString* firstName, *lastName; | |
-(NSString*)fullName; | |
@end | |
@implementation Person | |
+ (NSSet *)keyPathsForValuesAffectingFullName { | |
return [NSSet setWithObjects:@"lastName", @"firstName", nil]; | |
} | |
-(NSString*)fullName { | |
return [NSString stringWithFormat:@"%@ %@", self.firstName, self.lastName]; | |
} | |
@end | |
Person* person = [[Person alloc] init]; | |
person.firstName = @"jon"; | |
person.lastName = @"harris"; | |
[person addObserver:self forKeyPath:@"fullName.length" options:0 context:kvoContext]; | |
person.firstName = @"john"; // exception : | |
// *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot update for observer <ViewController 0x7fac03659d50> for the key path "fullName.length" from <Person 0x7fac035317c0>, most likely because the value for the key "fullName" has changed without an appropriate KVO notification being sent. Check the KVO-compliance of the Person class.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment