objective c - iOS: Check if coredata object still exists? -
i have problem 2 different view controllers. each 1 in tab bar of app. , 1 view controller influences other one. in tab bar item 1 (view controller 1) edit database objects. can add, delete , edit entities in database there.
in view controller 2, can select these entities , add subcategories these entities , edit them well. if within entity in view controller 2, switch view controller 1, delete entity , switch view controller 2, app crashes. of course, because model of view controller (the deleted entity) doesn't exist anymore. how can check in viewwillappear? doesn't work:
- (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; if(!self.myentity){ self.isnotexistinganymore = yes; nslog(@"yes;"); } }
nsmanagedobject has isdeleted method returns yes if object has been marked deletion in managed object context.
if context has been saved object deleted persistent store, managedobjectcontext method returns nil.
so covers both situations:
if (self.myobject.isdeleted || self.myobject.managedobjectcontext == nil) ...
Comments
Post a Comment