|[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]|
Something as simple as this doesn't work like you'd expect:Personally, I wouldn't have expected it to - after all, when key1 changes, that doesn't mean that key2 changes, just that a notification is triggered. If there was an automatic "cascade" of notifications, there could easily be nasty loops with unexpected behavior (say you added that key3 triggers key1, and you change key1, does key1 also get the notification because it passed through key2->key3->key1?).
[self setKeys:[NSArray arrayWithObject:@"key1"] triggerChangeNotificationsForDependentKey:@"key2"];
[self setKeys:[NSArray arrayWithObject:@"key2"] triggerChangeNotificationsForDependentKey:@"key3"];
Now [someObject setValue:anyValue forKey:@"key1"]. key2 will be updated, but no change notification for key3. Also, you can't do this:
I'm quite happy with simple explicit notification changes:
[self setKeys:[NSArray arrayWithObject:@"key1",@"key2"] triggerChangeNotificationsForDependentKey:@"key3"];
(since that's clear that key1 & key2 both trigger key3)
[snip][self setKeys:[NSArray arrayWithObject:@"singleKey"] triggerChangeNotificationsForDependentKeys:[NSArray arrayWithObjects:...]];If you find yourself with a datamodel that has this a lot, it's trivial to add (typed in mail):
Or in English, you can't easily make multiple keys dependent on a single key; you have to call [self setKeys:triggerChangeNotificationsForDependentKey:] with the same array over and over.
And "Bob's your uncle" (as they say).
Adopting bindings correctly requires a Major change in how you think of and structure your model, and if you're not careful you can end up making your code more complicated.This is very true - it is usually _much_ easier if you use bindings from the very start rather than try to add them to an existing project. But at this point of having used them, I'd hate to have to go back...(unfortunately, "let's set up a binding to do this" seems to be my current first solution for any problem, regardless if it is appropriate or not).
|>The problem with bindings (From: Drew McCormack <email@hidden>)|
|>Re: The problem with bindings (From: Steve Sims <email@hidden>)|
|>Re: The problem with bindings (From: Gwynne <email@hidden>)|
|>Re: The problem with bindings (From: Glenn Andreas <email@hidden>)|
Visit the Apple Store online or at retail locations.
Copyright © 2011 Apple Inc. All rights reserved.