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)")
}
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).
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)")
}