领域-如果使用iOS 11Swift,则无法向项目添加初始数据

问题描述

我正在使用swift开发适用于iOS的应用程序,并选择Realm作为数据库。我实现了如下所述,它将在AppDelegate.swift中首次使用该应用程序时复制默认数据。

func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {                

  let defaultRealmPath = Realm.Configuration.defaultConfiguration.fileURL!
  let bundleRealmPath = Bundle.main.url(forResource: "Seed",withExtension: "realm")

  if !FileManager.default.fileExists(atPath: defaultRealmPath.path) {
    do {
      try FileManager.default.copyItem(at: bundleRealmPath!,to: defaultRealmPath)
    } catch let error {
        print("error: \(error)")
      }
  } 

  return true
}
    

如果这是用户首次使用此应用,则应复制默认数据。 但是,如果我在iOS 13上进行了测试,则可以成功复制它,但是在iOS 11上,则不能复制。

如果在iOS 13中,“ FileManager.default.fileExists(atPath:defaultRealmPath.path)”的结果为“ false”(=文件不存在),但在iOS 11中,则“ FileManager.default”的结果.fileExists(atPath:defaultRealmPath.path)”为“ true”。

为什么会发生这种情况,我该如何解决这个问题?

我的领域版本是5.1.0。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...