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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -