I am trying to delete all objects inside one class. I found two possibilities inside Realms documentation. First there's the possibility to use realm.deleteAll(), which deletes the whole database and there's realm.delete(), which deletes one single object. Is there a way to delete all entries inside one Table/Class in a easy way?
Suppose you want to delete all objects of Notofications,
you can try this
let realm = Realm()
realm.write {
let allNotifications = realm.objects(Notifications)
realm.delete(allNotifications)
}
Here's an extension that does this:
extension Object {
static func deleteAll(`in` realm: Realm) throws {
let allObjects = realm.objects(self)
try realm.write {
realm.delete(allObjects)
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With