sguruapp@gmail.com
facebook vk instagram Телеграм youtube

Скопировать файл из пакета(Bundle.main) в путь назначения (каталог документов) - Copy from file (Bundle.main) to document directory - Swift 5


func CopyFilesToDocumentDirectory(){
let bundlePath = Bundle.main.path(forResource: "document", ofType: ".json")

let destPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!

let fileManager = FileManager.default

let fullDestPath = URL(fileURLWithPath: destPath).appendingPathComponent("document.json")

if fileManager.fileExists(atPath: fullDestPath.path){
print("Database file is exist")
print(fileManager.fileExists(atPath: bundlePath!)
)
}
else
{
do{
try fileManager.copyItem(atPath: bundlePath!, toPath: fullDestPath.path)
print("My doc path: \(fullDestPath.path)")
}
catch
{
print("\n",error)
}}}

Возврат к списку

обучись профессии будущего

Хочешь стать успешным разработчиком
приложений? Тогда добро пожаловать к нам.

обучись профессии будущего