Re: NSDictionaryController copies objects contained in the dictionary it is controlling?
Re: NSDictionaryController copies objects contained in the dictionary it is controlling?
- Subject: Re: NSDictionaryController copies objects contained in the dictionary it is controlling?
- From: Ron Lue-Sang <email@hidden>
- Date: Fri, 17 Oct 2008 18:10:19 -0700
On Oct 17, 2008, at 4:08 PM, Ron Aldrich wrote:
Folks,
I'm trying to use the new NSDictionaryController in a project I'm
working on, and I'm running into a bit of trouble.
I have a dictionary which contains a list of MB_Robot objects,
sorted by their unique IDs. Each MB_Robot provides the code
necessary to operate a single robotic device.
It is important that I only create a single object for each robot.
The problem I'm running into is that when I connect a
NSDictionaryController to the dictionary (in order to display it's
contents in a view), it attempts to copy the MB_Robot objects
(rather than simply keeping a reference to the original objects).
This results in the application terminating with:
2008-10-17 15:27:33.723 DiscFactoryTest[7030:10b] *** Terminating
app due to uncaught exception 'NSInvalidArgumentException', reason:
'*** -[MB_MXRobot copyWithZone:]: unrecognized selector sent to
instance 0x148a10'
Is this the expected behavior for NSDictionaryController? Is there
a way to stop it from copying objects?
Note that I have previously done much the same thing using
NSArrayController, without any objects being copied, so I really
don't understand why NSDictionaryController would be copying the
objects.
This is expected, but not documented. File a documentation bug that we
should note that the values for the dictionaryController's
keyValuePair objects require that the passed in object conform to
copying.
In the meantime, since you want your robot objects to be unique
anyway, you can implement the copying protocol in your robot obejcts
to return [self retain].
--------------------------
RONZILLA
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden