Reputation: 25
I'd like to delete databases of realm. I know how to delete that on Java, but I need to do that on swift
like this(Java):
RealmConfiguration realmConfig = new RealmConfiguration.Builder(this).build();
Realm.deleteRealm(realmConfig);
realm = Realm.getInstance(realmConfig);
thanks.
Upvotes: 1
Views: 506
Reputation: 2127
If you want to delete Realm's files
let manager = NSFileManager.defaultManager()
let realmPath = Realm.Configuration.defaultConfiguration.path as! NSString
let realmPaths = [
realmPath as String,
realmPath.stringByAppendingPathExtension("lock")!,
realmPath.stringByAppendingPathExtension("log_a")!,
realmPath.stringByAppendingPathExtension("log_b")!,
realmPath.stringByAppendingPathExtension("note")!
]
for path in realmPaths {
do {
try manager.removeItemAtPath(path)
} catch {
// handle error
}
}
From Realm's official documentation:
https://realm.io/docs/swift/latest/#deleting-realm-files
Upvotes: 2
Reputation: 4533
Best thing to do is to call deleteAll()
method on realm object like:
let realm = try! Realm()
try! realm.write {
realm.deleteAll()
}
Upvotes: 0