
二、填入下列程式碼,就可以了。
let dirPaths = NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask, true)
let docsDir:String! = dirPaths[0]
let destPath = (docsDir as NSString).appendingPathComponent("/db.sqlite")//這裡填入你的.sqlite
let fileMgr = FileManager.default
if let path = Bundle.main.path(forResource: "db", ofType:"sqlite")
{
if !fileMgr.fileExists(atPath: destPath)//如果db不存在,那就直接複製一份
{
do {
try fileMgr.copyItem(atPath: path, toPath: destPath)
print("success")//
}
catch let error as NSError
{
print(error.localizedDescription)
}
}else{
print(".sqlite已存在")//
}
}
沒有留言:
張貼留言