Search code examples
swiftrealmtruncate

Truncate table in Realm Swift


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?


Solution

  • 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)
        }