Newly created NSManagedObject returns temporary objectID even after save

前端 未结 2 1299
北海茫月
北海茫月 2021-02-07 09:39

Very simple situation. Not sure why it\'s causing an issue.

I have a view that creates a new NSManagedObject in a child NSManagedObjectContext. When the user presses \"

2条回答
  •  無奈伤痛
    2021-02-07 10:15

    Have you tried obtaining the permanent ID's for your objects? I've had success sharing NSManagedObjectID's between contexts by calling

    NSError *error = nil;
    [self.context obtainPermanentIDsForObjects:@[object1, object2]
                                         error:&error];
    

    followed by my save method. I structure my contexts in such a way that there is an I/O context which is the parent to my 'read context' (context used for my main thread activity) which is the parent to my background task contexts. Save in this case propagates all the way up the chain.

提交回复
热议问题