ios - How to delete selected tables using persistentStoreCoordinator -
i'm working on ios app developed using objective-c. have added module users when login store details user. app having code, when press logout button deletes entities database. using code below.
nsmanagedobjectcontext *managedobjectcontext = [self managedobjectcontext];
nserror *error = nil; // retrieve store url nsurl *storeurl = [[managedobjectcontext persistentstorecoordinator] urlforpersistentstore:[[[managedobjectcontext persistentstorecoordinator] persistentstores] lastobject]]; // lock current context [managedobjectcontext lock]; [managedobjectcontext reset];//to drop pending changes //delete store current managedobjectcontext if ([[managedobjectcontext persistentstorecoordinator] removepersistentstore:[[[managedobjectcontext persistentstorecoordinator] persistentstores] lastobject] error:&error]){ // remove file containing data [[nsfilemanager defaultmanager] removeitematurl:storeurl error:&error]; //recreate store in appdelegate method [[managedobjectcontext persistentstorecoordinator] addpersistentstorewithtype:nssqlitestoretype configuration:nil url:storeurl options:nil error:&error];//recreates persistent store } [managedobjectcontext unlock];
by keeping break points, understood retrieving url of database , deleting , re-creating it. lets have 3 tables a,b , c, want delete & b not c. reference- persistent store coordinator
is understanding correct? how can achieve this?
tia
try code
nsmanagedobjectcontext *context = [self managedobjectcontext]; [context deleteobject:managedobject]; nserror *error = nil; if (![context save:&error]) { nslog(@"can't delete! %@ %@", error, [error localizeddescription]); return; }
Comments
Post a Comment