Re: wasting space?
Re: wasting space?
- Subject: Re: wasting space?
- From: "Michael Ash" <email@hidden>
- Date: Mon, 6 Oct 2008 17:08:31 -0400
On Mon, Oct 6, 2008 at 4:22 PM, Erik Buck <email@hidden> wrote:
> I am no fan of KVO or bindings, but I disagree with Mike Ash on his analysis.
>
> If you are even tempted to override - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context, you have missed the whole point of KVO IMHO.
>
> Let the built in framework code parse the key paths. You should forget that key paths even exist.
>
> When someone calls float currentElevation = [someObject valueForKeyPath:@"document.currentTerrain.selectedObject.elevation"], that is conceptually identical to the following:
>
> currentElevation = [[[[someObject document] currentTerrain] selectedObject] elevation];
>
> In fact, the framework will call -document, -currentTerrain, -selectedObject, and -elevation for you if you let it. Just make sure someObject has a -document method, and your document object has a currentTerrain method, and your terrain object has a -selectedObject method and selected objects have an -elevation method, and you are good to go!
I am very confused here. KVO has nothing to do with a call like
valueForKeyPath:, other than the obvious fact that they are both built
on the idea of key paths. The
observeValueForKeyPath:ofObject:change:context: method doesn't
interact with valueForKeyPath: in any way, and so I don't really
understand what you're getting at here.
If you don't override observeValueForKeyPath:ofObject:change:context:,
how are you supposed to use KVO at all? As far as I understand it,
that is the *only* way to get notified of changes to things you
observe.
> If you ever find yourself writing switch statements based on the return value of a method you are doing something very wrong. If you have nested if statements comparing strings, you are doing something wrong.
I agree, but the KVO API doesn't leave you much choice unless you
simply forego KVO altogether.
Mike
_______________________________________________
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