如何判断NSManagedObject实例是否从上下文中删除?

时间:2017-11-09 11:34:11

标签: ios nsmanagedobject

众所周知,在“保存到持久存储”之后,将从其上下文中删除NSManagedObject。我想知道api可以帮我判断它是否被删除。

// MakeupModel is a subclass of NSManagedObject
MakeupModel *model = [MakeupModel MR_findFirstOrCreateByAttribute:@"materialId" withValue:@"221101010"];
model.materialId = model.materialId;
[MakeupModel MR_truncateAll];
[[NSManagedObjectContext MR_contextForCurrentThread] MR_saveToPersistentStoreAndWait];



// Code will crash here because model has beed deleteed whose properties could not be visited.  But model is not a "nil" object, how can I judge whether it is deleted? Is there any apis could help?
if(model.materialId) {

}

0 个答案:

没有答案