Answer the question
In order to leave comments, you need to log in
How to move a file from Assets to Documents?
Good day!
Please tell me how can I move the file from the database - KanjiDataBase.s3db - to Documents for its further use?
As I understand it, you need to work with this object
let asset = NSDataAsset(name: "KanjiDataBase", bundle: Bundle.main)
let fileManager = FileManager.default
// получаем полный путь к каталогу Documents
// объект класса NSURL
let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
if let documentUrl = urls.first {
print(documentUrl)
do{
try fileManager.copyItem(at: <как можно получить URL или Path для NSDataAsset пока не понимаю>, to: documentUrl)
}
catch {
print("error")
}
Answer the question
In order to leave comments, you need to log in
Happened,
let asset = NSDataAsset(name: "KanjiDataBase", bundle: Bundle.main)
// получаем полный путь к каталогу Documents
// объект класса NSURL
let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
if let documentUrl = urls.first {
try! asset?.data.write(to: documentUrl.appendingPathComponent("KanjiDataBase.s3db"), options: [.atomic])
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question