I have the choice of doing a migration, but I would prefer to delete everything in my defaultRealm(). How can I do this easily?
realm.deleteObject(object)
is the only function along with .deleteObjects.
I have tried the following code:
Method 1
realm.deleteObjects(RLMObject.objectsInRealm(realm, withPredicate: NSPredicate(value: true)))
Method 2
realm.deleteObjects(Dog.allObjectsInRealm(realm)) realm.deleteObjects(Person.allObjectsInRealm(realm)) realm.deleteObjects(Goal.allObjectsInRealm(realm)) realm.deleteObjects(Goals.allObjectsInRealm(realm))
Both fail to prevent the migration exception.
The right way of deleting your entire Realm (schema) is to use : Realm realm = Realm. getDefaultInstance(); realm. beginTransaction(); // delete all realm objects realm.
To delete all objects from the realm, call Realm. deleteAll() inside of a write transaction. This clears the realm of all object instances but does not affect the realm's schema.
The Realm React Native SDK allows you to use Realm Database and backend Apps from React Native applications for iOS and Android written in JavaScript or TypeScript.
Use deleteAll()
:
let realm = try! Realm() try! realm.write { realm.deleteAll() }
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