2017-09-28 30 views
0

我使用從Bundle.main.path獲取的路徑不能使用db.execute函數插入更新sqlite數據庫 沒有顯示錯誤,我不明白爲什麼,請幫我 下面是我的代碼Swift 3:db.execute不能使用獲取路徑使用Bundle.main.path

var config = Configuration() 
config.readonly = false 
config.foreignKeysEnabled = false 
enter code here 
let path1:String = Bundle.main.path(forResource: "data", ofType: "sqlite",inDirectory: "Data")! 
db = try DatabaseQueue(path: path1,configuration: config) 
-------------- 
try db.execute("update detail set favorite = \(newDetail.favorite!) where id = \(newDetail.id!)") 

回答

1

不能寫入到應用程序包中的文件,你必須複製sqlite的文件如文檔目錄並使用該副本保存您的數據。

+0

謝謝你支持我,我是新手,你能爲我創造一個榜樣嗎? –