ios - Delete all my data in my Core Data store -
i have followed variety of posts here in delete data app can start over. have tried:
a) deleting data:
nsarray *entities = model.entities; (nsentitydescription *entitydescription in entities) { [self deleteallobjectswithentityname:entitydescription.name incontext:context]; } if ([context save:&error]) { ... - (void)deleteallobjectswithentityname:(nsstring *)entityname incontext:(nsmanagedobjectcontext *)context { nsfetchrequest *fetchrequest = [nsfetchrequest fetchrequestwithentityname:entityname]; fetchrequest.includespropertyvalues = no; fetchrequest.includessubentities = no; nserror *error; nsarray *items = [context executefetchrequest:fetchrequest error:&error]; (nsmanagedobject *managedobject in items) { [context deleteobject:managedobject]; nslog(@"deleted %@", entityname); } }
b) delete physical data store:
nserror *error; nspersistentstore *store = [[self persistentstorecoordinator].persistentstores lastobject]; nsurl *storeurl = store.url; nspersistentstorecoordinator *storecoordinator = store.persistentstorecoordinator; [self.diskmanagedobjectcontext reset]; // there local instance variable disk managed context [storecoordinator removepersistentstore:store error:&error]; [[nsfilemanager defaultmanager] removeitematpath:storeurl.path error:&error]; _diskmanagedobjectcontext = nil;
c) perform step , step b
in combinations appears run no errors, whenever receive new data (via http service) , start adding re-initialized data store kinds of duplicate data , various data issues. have delete , reinstall app data clean enough re-initialize.
it should straightforward. user logs in. app data downloaded , saved in store. user logs out , logs in again or different id , new data brought down.
any ideas why above methods not working?
update:
i edited code above show saving context , removing data store file. still end bad leftover data. problem multiple contexts use? have 3 contexts use in app: ui-managed context, background context , disk-managed context. notification listener takes care of merging changes in background context disk managed context.
i have tried altering above code loop through objects in 3 contexts , set them nil. authentication code takes care of reinitializing contexts. still banging head on seems simple issue.
after
for (nsentitydescription *entitydescription in entities) { [self deleteallobjectswithentityname:entitydescription.name incontext:context]; }
save context
[context save:&error];
Comments
Post a Comment