I\'m playing around with realm (currently 0.85.0) and my application uses the database to store user-specific data such as the contacts of the current user. When the user de
In case someone stumbles on this question looking for a way to do this in Swift, this is just
DonamiteIsTnt's answer rewritten. I've added this function to a custom utility class so I can do MyAppUtilities.purgeRealm()
during testing & debugging
func purgeRealm() {
NSFileManager.defaultManager().removeItemAtPath(RLMRealm.defaultRealmPath(), error: nil)
}
Note: If you find yourself in need of clearing data you might just check out Realm's new realm.addOrUpdateObject()
feature which allows you to replace existing data by its primary key with the new data. This way you're not continually adding new data. Just replacing "old" data. If you do use addOrUpdateObject()
make sure you override your model's primaryKey
class function so Realm knows which property is your primary key. In Swift, for example:
override class func primaryKey() -> String {
return "_id"
}