SwiftData how to delete an entity

How do I delete all the rows in an entity and/or delete the entity all together in SwiftData?

Here is a function I used to delete an entity in core data for reference.

class func deleteEntity(entity: String) {
        let fetchRequest1: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: entity)//entity.fetchRequest()
        let batchDeleteRequest1 = NSBatchDeleteRequest(fetchRequest: fetchRequest1)
        _ = try?  PersistanceController.shared.container.viewContext.execute(batchDeleteRequest1)
        print("Deleting coredata entity: \(entity)")
    }

For batch deletes, you're probably looking for ModelContext.delete(model:where:includesubentities:).

For individual objects, there's ModelContext.delete(_:).

This works fine for me. All entities in Group Model are deleted (and all subentities, @RelationShip delete rule is set to .cascade) :

private func deleteAll() {
        print("delete all!")
        do {
            if try modelContext.delete(model: Group.self, where: NSPredicate(value: true), includeSubentities: false) {
                print("OK Groups cleared !")
                 // what to triggers UI update, or @Query ?
            } 
        } catch {
            print("error: \(error)")
        }
    }

But, no trigger of UI/Query update…

SwiftData how to delete an entity
 
 
Q