On Aug 16, 2011, at 13:14 , Andrew Kinnie wrote:

> Hmm.  Well the generated code was created by Xcode 4's "Create 
> NSManagedObject Subclass" based on the model.   The properties are created 
> along with the methods, however due to an earlier issue, I changed @dynamic 
> to @synthesize for the various properties in the .m for Article and 
> MediaResource.  There are no ivars.  Apparently this caused the problem.  
> Changing it back to @dynamic fixed it.
> 
> Further debugging indicated that when I deleted an article, using 
> 
> [self.moc deleteObject:myArticle];
> 
> and at the point that is called, the article had a media object in it's media 
> relationship (doing po myArticle in the debugger indicates this) but when I 
> click continue, it lands on a breakpoint in the removeMediaObject method in 
> Article, and the value passed in exists, but the media relationship itself 
> contains no objects.  That is where the crash occurred.  So apparently, Core 
> Data was doing the cascade delete, then because I had "@synthesize" instead 
> of "@dynamic" it called the class's removeMediaObject method trying to remove 
> the object that is no longer in the relationship, thus it breaks by calling 
> removeObject" on the __NSSet0 singleton object.

If you change a Core Data model property from @dynamic to @synthesize, then it 
isn't using Core Data any more -- it's using ivars for the property backing 
store instead. That means you end up with 2 properties with the same name -- 
the model-derived property that Core Data knows about, and the subclass-derived 
property that the rest of your app knows about. No wonder that crashes start to 
occur.

You *cannot* swap @synthesize and @dynamic for a Core Data property, not ever. 
You can replace the Core Data implementation (the @dynamic one, so to speak) 
with your own implementation. Just not the @synthesize'd one. Not ever.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to