开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜