ios - 清除设备上的数据库(Sqlite)

标签 ios database swift sqlite swift2

我使用SwiftData在swift中创建sqlite数据库,数据库在模拟器上工作,但是当我想在真实设备上运行应用程序时,它不起作用,并且错误是没有这样的表,我该如何解决这个问题?

  let fileMan = NSFileManager.defaultManager()
        if (fileMan.fileExistsAtPath(dbPath)){
            if let source = NSBundle.mainBundle().resourcePath?.stringByAppendingPathComponent(databaseStr){
                if (fileMan.fileExistsAtPath(source)){

                    print("SQLiteDB - file \(databaseStr) not found in bundle")
                } else {
                  //  var error: NSError?
                    do {
                    try fileMan.copyItemAtPath(dbPath, toPath: source )


                    } catch _ {

                    }

                }

            }

        }
        return dbPath

    }

最佳答案

从设备中删除应用程序并清理项目在很多情况下都会有所帮助。

如果仍然不起作用,请尝试打开 sqlite 数据库。 firefox sqlite-manager

但我认为最简单的解决方案是删除数据库并创建一个新数据库。删除后,您还需要从设备和模拟器中删除该应用程序。

关于ios - 清除设备上的数据库(Sqlite),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35411004/

相关文章:

java - 正在使用 query.getResultList();方法对性能有严重影响?

swift - 如何编辑 UIBlurEffect 强度?

ios - 将图像转换为黑白同时保留 alpha channel

ios - 覆盖只读属性以使其读写

ios - 使用 pickerView 填充多个部分 tableView

iphone - 警告:属性不可用

c# - 如何从内部保护系统(如内部工作)?

sql - DB2 字段值替换

ios - Xcode 8 SiriKit 扩展 - 无法附加到 pid

ios - Xcode UI 测试 - 如何在 WebView 中查找和点击()元素