Answers for "filemanger save data to filepath"

0

save file with % swift

func getDocumentsDirectory() -> URL {
    let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    return paths[0]
}
Posted by: Guest on October-24-2020
0

save file with % swift

let str = "Super long string here"
let filename = getDocumentsDirectory().appendingPathComponent("output.txt")

do {
    try str.write(to: filename, atomically: true, encoding: String.Encoding.utf8)
} catch {
    // failed to write file – bad permissions, bad filename, missing permissions, or more likely it can't be converted to the encoding
}
Posted by: Guest on October-24-2020

Code answers related to "Swift"

Browse Popular Code Answers by Language