Realm fileExists is always true

谁说胖子不能爱 提交于 2019-12-20 06:33:26

问题


I want to copy preloaded realm file, so I do:

Copied my file to project navigator named default.realm. Then check if fileExists::

let bundlePath = Bundle.main.path(forResource: "default", ofType: "realm")
let destPath = Realm.Configuration.defaultConfiguration.fileURL?.path
let fileManager = FileManager.default
if fileManager.fileExists(atPath: destPath!) {
    //File exist, do nothing
    print("File exist")
} else {
    do {
        //Copy file from bundle to Realm default path
        try fileManager.copyItem(atPath: bundlePath!, toPath: destPath!)
        print("Copied")
    } catch {
        print("\n",error)
    }
}

And it always returns true, so I can't copy my realm file.


回答1:


I ran your code in Simulator after resetting the contents and settings (Simulator > Reset Content and Settings...) and it appeared to execute as intended.

If you've previously used Realm in your project (i.e. testing), it's probably seeing the old default.realm file.



来源:https://stackoverflow.com/questions/43545490/realm-fileexists-is-always-true

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!