How can I associate an NSManagedObject to the context after it has been initialised?

后端 未结 2 1162
谎友^
谎友^ 2021-01-18 20:04

For example, if I have an NSManagedObject named Items, and I want to set the ManagedObjectContext later (not when initialised), how wo

2条回答
  •  野的像风
    2021-01-18 20:28

    The standard init method for an NSManagedObject subclass is -initWithEntity:insertIntoManagedObjectContext:. If you don't provide a context, call:

    [myManagedObjectContext insertObject:item];
    

    ...which is what the init method does internally. You'll still need to save the managedObjectContext as usual.

提交回复
热议问题