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
}func getDocumentsDirectory() -> URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0]
}
Also in Swift:
- how to change background color swift
- uilabel font size swift
- dark mode change immediately swift
- swift image button blue
- oops with swift
- swift how to call a function
- remove and element from array firebase swift 5
- swift xcode debug cannot see code backtrace
- swift convert dictionary to json
- remove all add TapGestureRecognizer swift
- horizontal slide segue swift
- context.fetch() in swift
- swift file size from url
- run a function only once swift
- swift close app
- convert string to int swift
- localized string format swift
- swift store enum case string values in firebase
- swift add navigation bar
- swift retrieve value from dictionary
- urlencode string swift
- how to loop swift
- get height of navigation bar swift
- remove last character from string swift