project-imas / encrypted-core-data

v2.0 - iOS Core Data encrypted SQLite store using SQLCipher
Other
785 stars 236 forks source link

How to delete all the objects from encrypted core data #322

Open Rahul0106231 opened 5 years ago

Rahul0106231 commented 5 years ago

i have a requirement when a new user logs in to the device which is already registered to another user . i need to delete all the data pertaining to the previous user present in coredata. i'm using batch delete to perform the operation , but it throws an error . here's the piece of code i'm using to delete the objects.Is there a prescribed way to delete all the entities in coredata in quickest way possible..

do { try self.persistentContainer.managedObjectModel.entities.forEach { (entity) in if let name = entity.name { let fetch = NSFetchRequest(entityName: name) let request = NSBatchDeleteRequest(fetchRequest: fetch) try self.viewContext.execute(request) } } self.saveMainContext() } catch let error as NSError{ DDLogError("Could not Reset The Database (error.userInfo)") }

chadbag commented 4 years ago

We had to get rid of the NSBatchDeleteRequest, IIRC, and fetch all the data and delete it in a loop (like you had to do before the batch delete was available).

glaurent commented 4 years ago

It seems batch requests are not supported :-/