How to completely remove Realm database from iOS?

前端 未结 7 1357
情书的邮戳
情书的邮戳 2020-12-15 08:32

Now I get error Property types for \'value\' property do not match. Old type \'float\', new type \'double\' How to clear database or migrate is successfully?

7条回答
  •  有刺的猬
    2020-12-15 09:30

    Swift 4.2 To remove database:

    func remove(realmURL: URL) {
            let realmURLs = [
                realmURL,
                realmURL.appendingPathExtension("lock"),
                realmURL.appendingPathExtension("note"),
                realmURL.appendingPathExtension("management"),
                ]
            for URL in realmURLs {
                try? FileManager.default.removeItem(at: URL)
            }
    let url = Realm.Configuration.defaultConfiguration.fileURL!
    remove(realmURL: url)
    

    To clear database:

    try? realm.write {
        realm.deleteAll()
    }
    

提交回复
热议问题