What's the fastest and easiest way to create a new managed object?
When I have a subclass of NSManagedObject, I could do this:
Friend *newFriend = (Friend*)[[NSManagedObject alloc] initWithEntity:@"Friend"
insertIntoManagedObjectContext:moc];
But since I have a subclass, couldn't I simply instantiate it another way so that I don't have to tell it what Entity it is? (I mean: Is there already an predefined initializer for this, or must I write my own开发者_高级运维?)
Besides initWithEntity:insertIntoManagedObjectContext:
the only two methods you can use to customize object initialization are awakeFromInsert
and awakeFromFetch
. See the full discussion related to Core Data object initialization here.
精彩评论