Save File With Swift

[Solved] Save File With Swift | Swift - Code Explorer | yomemimo.com
Question : save file with % swift

Answered by : quaint-quail-rblyi6q3wthz

func getDocumentsDirectory() -> URL { let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) return paths[0]
}

Source : https://www.hackingwithswift.com/example-code/strings/how-to-save-a-string-to-a-file-on-disk-with-writeto | Last Update : Sat, 31 Oct 20

Question : save file with % swift

Answered by : quaint-quail-rblyi6q3wthz

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
}

Source : https://www.hackingwithswift.com/example-code/strings/how-to-save-a-string-to-a-file-on-disk-with-writeto | Last Update : Sat, 31 Oct 20

Answers related to save file with swift

Code Explorer Popular Question For Swift