Re: Curious about copyWithZone message from NSArrayController in "GC required" project
Re: Curious about copyWithZone message from NSArrayController in "GC required" project
- Subject: Re: Curious about copyWithZone message from NSArrayController in "GC required" project
- From: Bill Bumgarner <email@hidden>
- Date: Sat, 12 Jan 2008 21:31:32 -0800
On Jan 12, 2008, at 8:03 PM, Luke Evans wrote:
I have a "gc required" project with some entities in a CoreData
model, each with requisite subclasses of NSManagedObject.
In particular, I have an entity/class 'A' that declares a property
returning an NSArray (which actually returns an ordered list of
entity/class 'B' that is defined as a to-many relationship on the
entity A).
Now, in my UI, I have a couple of NSArrayControllers. One of these
obtains the 'A's from the managed object context, and provides
instances to UI that in turn uses an NSArrayController bound to the
property of 'A', such that all the 'B's of a given 'A' are returned
in the correct order.
Now, all this is now working correctly (as far as I can tell), but
before I got it to work as expected, I had to fix a problem logged
in the console as:
*** -[B copyWithZone:]: unrecognized selector sent to instance
0x127f310
The obvious fix of implementing a 'dumb' copyWithZone in the B class
(that
First and foremost, -copyWithZone: has absolutely nothing to do with
the differences between GC and non-GC. As its name implies, it is all
about copying an object, something that must be done in either GC or
non-GC.
returns B's 'self' ) got past the problem, but it raises a number of
questions in my Cocoa n00b's mind:
1. Why am I being asked to create a copy of B instances anyway? I
would have thought that NSArrayController could work quite happily
with a reference to my original B's - at least in the GC context.
Indeed, forcing this to happen with a trivial implementation of
copyWithZone seems to work happily.
If you are ever causing a -copyWithZone: to be sent to an
NSManagedObject or subclass therein, then there is something seriously
wrong with your code.
NSManagedObjects cannot be copied via -copyWithZone: for a reason; it
doesn't make sense to do so without taking the model into
consideration -- without fully traversing the relationships and
considering exactly how the copy should be done within the bounds of
the managed object model.
So -- first question -- what is triggering the -copyWithZone: being
sent to an instance of B in the first place?
b.bum
_______________________________________________
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