I am a little confused as to how to delete all core data in swift. I have created a button with an IBAction
linked. On the click of the button I have the follow
static func fetch(entity: T.Type, withPredicate predicate: NSPredicate? = nil) -> Array? where T : NSManagedObject {
let request: NSFetchRequest = NSFetchRequest(entityName: String(describing: T.self))
request.predicate = predicate
do {
return try context.fetch(request)
}catch{
print(error.localizedDescription)
}
return nil
}
static func delete(_ object: T) where T : NSManagedObject {
context.delete(object)
saveContext()
}
static func reset(entity: T.Type) where T : NSManagedObject {
fetch(entity: entity.self)?.forEach{
delete($0)
}
}