Take for example the following:
Project *project = [[Project alloc] init];
project.title = @"MyProject";
project.field = @"SomeOtherField";
I want to set a flag whenever a property is changed. Is there any way this can be done when the property changed is done via dot syntax?
I could just overwrite
- (void) setValue:(id)value forKey:(NSString *)key
And set the object properties using KVC:
[project setValue:@"SomeOtherField" forKey:@"field"];
But the dot syntax always looks cleaner 😉
Thanks!
Use
Key-Value Observingif you will be doing this with more than one property/object.Register as an observer:
Implement the change handler