Re: Debugging Bindings
Re: Debugging Bindings
- Subject: Re: Debugging Bindings
- From: Guy English <email@hidden>
- Date: Fri, 28 Jan 2005 11:34:26 -0500
> NSMutableArray *tempRobots = robots;
> [tempRobots addObject:newRobot];
> [self setRobots:tempRobots];
> and that works just fine.
Well ok ...
but it should be ...
[self willChangeValueForKey: @"robots"];
[robots addObject: newRobot];
[self didChangeValueForKey: @"robots"];
Your code works because you call setRobots - which automatically
triggers the KVO notifications. You're doing more work than you need
to though. Inside setRobots newRobots == robots so you end up with:
[robots retain];
[robots release];
robots = robots;
and the KVO (changeValueForKey) stuff has been done for you. It's not
really great form because a casual reader won't really get *why*
you're doing what you're doing. Triggering the KVO stuff is better
form I think.
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