On Mon, Oct 6, 2008 at 4:22 PM, Erik Buck <[EMAIL PROTECTED]> 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 protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
