ios - deleting records that has recursive relationships in coredata -
i have below relationship in model. userstatement has levelupstatement , parentstatement has a-to 1 relationship between. problem have when try delete levelupstatement. have nullify both end of relationship , when try delete below: (mainuserstatement parentstatement)
self.mainuserstatementmodel.levelupstatement = nil; self.mainuserstatementmodel.levelupterm = nil; [[ashcoredatastack defaultstack].managedobjectcontext deleteobject:self.mainuserstatementmodel.levelupstatement]; error getting is: terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-deleteobject: requires non-nil argument'. i know managedobjectcontext exists. problem should not there. how can safely delete levelupstatement without effecting levelupterm , parentstatement?

you need change order of lines of code:
[[ashcoredatastack defaultstack].managedobjectcontext deleteobject:self.mainuserstatementmodel.levelupstatement]; self.mainuserstatementmodel.levelupstatement = nil; self.mainuserstatementmodel.levelupterm = nil; in fact, if parentstatement relationship set 'nullify' not need second of these lines: coredata automatically nil out levelupstatement. check relationship in data model inspector:

Comments
Post a Comment