Re: Debugging Bindings
Re: Debugging Bindings
- Subject: Re: Debugging Bindings
- From: Guy English <email@hidden>
- Date: Fri, 28 Jan 2005 14:01:22 -0500
[ code snipped ]
> Oh well that's even better!
Yeah ... well it'll work. As Mmalc pointed out it tells observers that
you've updated the entire array. To be more specific about what you've
done to it you could:
NSIndexSet *indexes = [NSIndexSet indexSetIndex: [robots count]];
[self willChange:NSKeyValueChangeInsertion valuesAtIndexes:indexes
forKey:@"robots"];
[robots addObject: newRobot];
[self didChange:NSKeyValueChangeInsertion valuesAtIndexes:indexes
forKey:@"robots"];
That code lets observers know that you've add one object and where in
the array it's been inserted. If you write observer methods this kind
of information is nice since it means you know exaclty whats just
happened to your collection. I cribbed the above code almost directly
from the bottom of Mmalcs page:
http://homepage.mac.com/mmalc/CocoaExamples/controllers.html
Really, it's worth reading to get a handle on the bindings thing. The
final solution looks more complex but, in the end, it is the most
efficient because it offers the most context to observers.
> Really, I'm quite new to all this in general. First Cocoa App, first
> time using Objective C, first try at bindings. I'm bound to make lots
> of stupid mistakes and not even know which docs to read!
Naw, nothing really stupid. Bindings take a bit of a leap to get used
to. I've used Cocoa since about '97 and I'm still getting corrected on
the bindings thing. :)
Take care,
Guy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden