objective c - Use NSManagedObject's own context property to delete it? -
it may kinda naive wondering if correct use following statement delete managed object persistent store of core data:
[managedobject.managedobjectcontext deleteobject:managedobject];
i ran above in xcode debugger - didn't complain object's content still there. context referenced through object deleted, , causing memory lock preventing deletion of object?
in regards content persisting, still need call save: on context after deleting object.
i can't answer if have issue referencing managedobjectcontext in managedobject use 'datamanager' manage managedobjectcontext. below example of delete method used in 1 of datamanagers:
- (void)deletereport:(report*)areport incontext:(nsmanagedobjectcontext*)context { if (areport != nil) { if (context == nil) { context = self.managedobjectcontext; } context.mergepolicy = nsmergebypropertystoretrumpmergepolicy; [context deleteobject:areport]; nserror *error = nil; [context save:&error]; if (error) { //nslog(@"%@", error); } }}
edit: clarification, report in method instance of nsmanagedobject, , method takes nsmanagedobjectcontext parameter, because application pulled supports use of multiple contexts.
Comments
Post a Comment