Core Data: Custom to-many relationship setter not being invoked
Core Data: Custom to-many relationship setter not being invoked
- Subject: Core Data: Custom to-many relationship setter not being invoked
- From: Ken Tabb <email@hidden>
- Date: Mon, 22 Feb 2010 22:59:07 +0000
Hi folks,
I'm clearly doing something daft but unable to see the error of my ways.
Distilling my problem down into the Department & Employees example, both are custom NSManagedObject subclasses, each with an inverse to-many / to-one relationship as you'd expect. My problem is that Department's custom -awakeFromInsert gets called, yet its -addEmployeesObject and -addEmployees methods don't ever get called. If I add employees in the app, it all works swimmingly, but my custom accessors aren't ever used.
As per searches on why custom Core Data accessors aren't being called, I've checked the model specifies that the Department entity specifies the custom class (which it does, no matter how many times I keep checking it). And it must be, else the custom -awakeFromInsert wouldn't be firing. Ditto the Employee entity specifies the Employee class.
The custom accessors are as per Xcode's Design -> Data Model -> Copy Obj-C 2.0 Method Invocations / Declarations to Clipboard, I'm doing nothing clever with them (in this sample app). It makes no difference if I use the Obj-C 1.0 templates from the same menu either.
Can't figure out why the initialiser is being called, but not the custom setters.
On the other hand the Employee class can have a custom -setDepartment like so:
- (void)setDepartment:(Department *)value
{
[self willChangeValueForKey:@"department"];
[self setValue:value forKey:@"primitiveDepartment"];
[self didChangeValueForKey:@"department"];
}
... which does get called. Sob...
I wouldn't mind so much if the app didn't actually work correctly, but that it's deliberately ignoring my lovely custom accessors is a slap in the face...
Thanks in advance for any "you stupid idiot you need to do this, man" replies :)
Cheers,
Ken
. . . . . . . . . . . . . . . . . . . . . . . . . . .
Dr. Ken Tabb
Mac & UNIX programmer
Neural network & computer vision researcher
University of Hertfordshire, UK
_______________________________________________
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