Delete All Objects of a Type
To delete all objects of a type from a realm:
Open a write transaction with
realm.write()orrealm.writeBlocking().Query the transaction's mutable realm with
realm.query(). Specify the object type as a type parameter passed toquery().Delete the set of
RealmResultsreturned by the query withrealmResults.delete().
realm.write {
// fetch all frogs from the realm
val frogs: RealmResults<Frog> = this.query<Frog>().find()
// call delete on the results of a query to delete those objects permanently
frogs.delete()
}
note
You can only delete objects in a realm within a write transaction.