Clearing CoreData and all that inside

后端 未结 4 667
日久生厌
日久生厌 2021-02-08 09:32

I\'m pretty new to CoreData and this app that uses it. And I\'m currently working on a feature that clears the entire core data when I log out in the app.

I have 2 sqlli

4条回答
  •  执念已碎
    2021-02-08 10:22

    try the following method to flush the database, it works perfect for me.

    -(void) flushDatabase{
        [__managedObjectContext lock];
        NSArray *stores = [__persistentStoreCoordinator persistentStores];
        for(NSPersistentStore *store in stores) {
           [__persistentStoreCoordinator removePersistentStore:store error:nil];
           [[NSFileManager defaultManager] removeItemAtPath:store.URL.path error:nil];
        }
        [__managedObjectContext unlock];
        __managedObjectModel    = nil;
        __managedObjectContext  = nil;
        __persistentStoreCoordinator = nil;
    }
    

提交回复
热议问题