Re: NSDocument and KVO compliance
Re: NSDocument and KVO compliance
- Subject: Re: NSDocument and KVO compliance
- From: Jerry Krinock <email@hidden>
- Date: Sat, 19 Oct 2013 09:27:14 -0700
On 2013 Oct 19, at 03:38, email@hidden wrote:
> I don't know if this is a common technique but I use it regularly to track binding changes.
>
> - (void)setValue:(id)value forKeyPath:(NSString *)keyPath
> {
> // all bindings that reference self (such as self.representedObject.xxx)
> // will pass through this method
> if ([keyPath rangeOfString:@"self.representedObject."].location != NSNotFound) {
> [self.document updateChangeCount:NSChangeDone];
> }
> [super setValue:value forKeyPath:keyPath];
> }
That's interesting and I've never seen it done.
I'd call it a variation of writing custom accessors for each attribute. Custom accessors for each attribute have the advantage of reliably catching all model changes, not just those driven by Cocoa Bindings. But your technique is way less code, by a factor of the number of attributes, and requires zero maintenance.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden