在设备上清除数据库(Sqlite)

时间:2016-02-15 13:46:05

标签: 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

    }

1 个答案:

答案 0 :(得分:0)

在许多情况下,从设备中删除应用程序并清理项目有用。

如果仍然无效,请尝试打开sqlite数据库。 firefox sqlite-manager

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