Realm.io Removing the realm file

478 Views Asked by At

My question, how can I properly remove a realm file? Currently I'm doing so using the file manager, which is fine for me since the Realm file is mostly here for offline caching.

My app logs in to a web-platform, and creates a realm for this platform so you can log in to multiple. When you remove it with the filemanager however, there can still be lock files and such so I guess this dirty way of removing is the wrong way!

in Android you have the deleteRealmFile call on the RealmClass, which works fine when all references are closed. It seems there is not much security on iOS as I can just remove it like this.

So what is the proper way of handling this?

I'm not sure if realm is intended to be used like this but it's ideal for us and makes the developers happy.

I'm working in swift and have an iOS7+ requirement.

1

There are 1 best solutions below

1
On BEST ANSWER

That is the proper way of deleting it. You can check the Migration example in the RealmExample project that come with the SDK and see that that's exactly how they do it, so I assume the recommended way.

let defaultPath = Realm.defaultPath
NSFileManager.defaultManager().removeItemAtPath(defaultPath, error: nil)