Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BadWolf13

macrumors 6502
Original poster
Dec 17, 2009
271
0
I've been programming with Obj-C for a few months now, but I'm new to this whole Core Data thing. Now so far, most of my model objects have required that I override the (id)init method, so as to properly initialize the object. Now so far in the tutorials, the book I've been working through, and examples online, I've only seen one person override the (id)init method in a subclass of NSManagedObject. In this example, instead of calling

Code:
[super init]

they called

Code:
[self initWithEntity: tEntityDescription insertIntoManagedObjectContext: theMOC];

Is this a required step in overriding the (id)init with a NSManagedObject subclass, or would I still be good with the way I've done with non-core data objects?
 
Yes, you need to use the initWithEntity: method. You should be to able use init in your subclass, just make sure you call that method on self/super.

The docs say:
Important: This method is the designated initializer for NSManagedObject. You should not initialize a managed object simply by sending it init.
 
You can overrride init, but I would be careful, you'll need some sort of shared NSManagedObjectContext which will be trouble if you want to do any threading.
 
You can overrride init, but I would be careful, you'll need some sort of shared NSManagedObjectContext which will be trouble if you want to do any threading.

Sorry, I'm kind of lost with what you're saying here. My understanding is that the NSManagedObjectContext looks over the objects, so why/how would I share it, and what exactly would I be sharing it with?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.