Re: Lion doesn't like tricky.key.paths in bindings?
Re: Lion doesn't like tricky.key.paths in bindings?
- Subject: Re: Lion doesn't like tricky.key.paths in bindings?
- From: Charles Srstka <email@hidden>
- Date: Fri, 29 Jul 2011 02:23:00 -0500
On Jul 28, 2011, at 9:42 PM, Kyle Sluder wrote:
> If you're not returning precisely the same NSString instance every
> time KVO thinks you should, then you are violating the rules and KVO
> has every right to complain.
>
> KVO doesn't do an -isEqual: on the result of your method. It does
> pointer equality. Something changed on Lion that causes it to now care
> that the return value of your method stays constant when it should.
But doesn’t that undermine the whole idea of encapsulation? Suppose I have an object that represents a file in the file system, and it’s got a property that represents a path:
- (NSString *)path {
return [[someStringIvar retain] autorelease];
}
- (void)setPath:(NSString *)newPath {
if(newPath != someStringIvar) {
[someStringIvar release];
someStringIvar = [newPath copy];
}
}
But later on, I refactor the object so that it uses URLs instead of paths, but I want to leave the -path method there for callers that might still be using the old interface, so I rewrite it like this:
- (NSURL *)URL {
return [[someURLIvar retain] autorelease];
}
- (void)setURL:(NSURL *)newURL {
if(newURL != someURLIvar) {
[someURLIvar release];
someURLIvar = [newURL copy];
}
}
- (NSString *)path {
return [[self URL] path];
}
- (void)setPath:(NSString *)newPath {
[self setURL:[NSURL fileURLWithPath:newPath]];
}
So what you are telling me is that even though the new -path method will return a string containing the same value every time, since it’s not going to be the same *pointer*, this is going to foul up bindings? That in order for bindings to work properly, all the accessors can’t do anything but naïvely return some instance variable directly, so that you might as well just be using a struct?
Why the heck would you design something like this?
Charles_______________________________________________
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