Re: Debugging Bindings
Re: Debugging Bindings
- Subject: Re: Debugging Bindings
- From: mmalcolm crawford <email@hidden>
- Date: Fri, 28 Jan 2005 10:20:37 -0800
On Jan 28, 2005, at 8:34 AM, Guy English wrote:
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"];
Sorry, but strictly speaking not quite. This sends a notification that
the whole array has changed, which is not the case. You've only
inserted one object. See the final "Batch import into an array, and
other mass changes" section at
<http://homepage.mac.com/mmalc/CocoaExamples/controllers.html> for an
example of sending a notification for an array insertion (also final
section at
<http://developer.apple.com/documentation/Cocoa/Conceptual/
KeyValueObserving/Concepts/AutoVsManual.html>).
In many respects the easiest way of abstracting this is still probably
to implement and use indexed accessor methods
(<http://developer.apple.com/documentation/Cocoa/Conceptual/
KeyValueCoding/Concepts/AccessorConventions.html>) -- you can generate
them automatically with Accessorizer
(<http://www.kevincallahan.org/software/accessorizer.html>) so it's not
as painful as it might be.
mmalc
_______________________________________________
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