B
B
badtrips2018-11-19 21:39:33
iOS
badtrips, 2018-11-19 21:39:33

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)

but I don't know what to do next. Is it somehow possible to move it using the FileManager, having received links to the source file and specifying the folder for copying?
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")
            }

Its properties:
spoiler
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"data" : [
{
"idiom" : "universal",
"filename" : "KanjiDataBase.s3db"
}
]
}
5bf3027746275300193947.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
badtrips, 2018-11-19
@badtrips

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 question

Ask a Question

731 491 924 answers to any question