How can I easily delete all objects in a Realm How can I easily delete all objects in a Realm ios ios

How can I easily delete all objects in a Realm


Use deleteAll():

let realm = try! Realm()try! realm.write {    realm.deleteAll()}


As of v0.87.0, there is a deleteAllObjects method on RLRealm that will clear the Realm of all objects.


Things have moved on in the Realm world - in case anyone comes across this now, there is a property that can be set:

Realm.Configuration.defaultConfiguration.deleteRealmIfMigrationNeeded = true

It then does as advertised. (btw: a lot of the syntax above has changed in case you are trying any of the other methods)

The Github PR https://github.com/realm/realm-cocoa/pull/3463