Lion doesn't like tricky.key.paths in bindings?
Lion doesn't like tricky.key.paths in bindings?
- Subject: Lion doesn't like tricky.key.paths in bindings?
- From: Jerry Krinock <email@hidden>
- Date: Fri, 22 Jul 2011 23:26:40 -0700
In Interface Builder, I often set a binding like this:
Bind to: FooController (an NSObjectController, instantiated in nib)
Controller Key: selection (an instance of Foo)
Model Key Path: barDate.someFormattingMethod
where 'barDate' is an NSDate attribute of 'foo' and 'someFormattingMethod is, for example, a method I've defined in a category of NSDate which formats the receiver into a string. I realize the normal way to do this is with a value transformer, but someone showed me this trick a few years ago, and I've found it to be more convenient and cohesive than value transformers.
Until Lion. I've had to rip out several of these recently because, upon changing the content object of the FooController object controller, Cocoa will raise an exception and log one of these turds:
Cannot remove an observer <NSObjectController 0x14a2c950> for the key path "barDate.someFormattingMethod" from <Foo 0x12ebbf50>, most likely because the value for the key "barDate" has changed without an appropriate KVO notification being sent. Check the KVO-compliance of the Foo class.
The problem is solved by either using a value transformer or defining a -barDateString and binding to this simple key instead:
Model Key Path: barDateString
Added methods in Foo class:
- (NSString*)barDateString {
return [[self barDate] someFormattingMethod] ;
}
+ (NSSet*)keyPathsForValuesAffectingBarDateString {
return [NSSet setWithObjects:
@"barDate",
nil] ;
}
Is there anything wrong with my original tricky key path? Why doesn't Lion like it?
Thanks,
Jerry Krinock_______________________________________________
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