Re: Debugging Bindings
Re: Debugging Bindings
- Subject: Re: Debugging Bindings
- From: Jason Harris <email@hidden>
- Date: Fri, 28 Jan 2005 16:29:22 -0700
David,
You've got a mutable to-many relationship in your TRobot class, so to
get automatic key-value observing when you change something, you need
to implement all of these methods:
- (id)robots;
- (void)setRobots: (id)newRobots;
- (unsigned int)countOfRobots;
- (id)objectInRobotsAtIndex: (unsigned int)index;
- (void)insertObject: (id)robot inRobotsAtIndex: (unsigned int)index;
- (void)removeObjectFromRobotsAtIndex: (unsigned int)index;
If you implement these and use them to add/remove stuff from your
NSMutableArray of robots, key-value observing will "just work". So,
for example, instead of calling setRobots and replacing your robots
ivar, you can do this:
int index = [self countOfRobots];
[self insertObject: newRobot inRobotsAtIndex: index];
Doing this will let your observer receive a nice change dictionary that
shows what sort of change occurred, and makes it easier to implement
undo, for example.
Jason
_______________________________________________
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