领域fileExists始终为true [英] Realm fileExists is always true

查看:86
本文介绍了领域fileExists始终为true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想复制预加载的领域文件,所以我这样做:

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

将我的文件复制到名为default.realm的项目导航器中.然后检查fileExists::

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)
    }
}

它总是返回true,所以我不能复制我的领域文件.

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

推荐答案

重置内容和设置(Simulator > Reset Content and Settings...)后,我在Simulator中运行了代码,它似乎已按预期执行.

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

如果您以前在项目中使用过Realm(即测试),则可能是看到了旧的default.realm文件.

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

这篇关于领域fileExists始终为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆