swift save data to file
let file = "file.txt" //this is the file. we will write to and read from it
let text = "some text" //just a text
if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
let fileURL = dir.appendingPathComponent(file)
//writing
do {
try text.write(to: fileURL, atomically: false, encoding: .utf8)
}
catch {/* error handling here */}
//reading
do {
let text2 = try String(contentsOf: fileURL, encoding: .utf8)
}
catch {/* error handling here */}
}
Also in Swift:
- swift image button blue
- get icloud doc swift
- convert secondsfrom1970 to date swift
- remove back button swift
- swift how to animate constraint change
- swift how to call a function
- swift close app
- how to set the center in view in swift
- how to get index path cell collection view from ui longpress gesture swift
- switch statements swift
- jar not declared js
- swift switch
- variadic parameters swift
- change textfield placeholder color swiftui
- swift create uinavigationcontroller programmatically
- create alert in swift
- swift generate uuid
- swift bring something to front of view
- get current unix timestamp swift ios
- Browse Swift s
- get height of navigation bar swift
- remove all add TapGestureRecognizer swift
- swift enum
- swift access appdelegate from viewcontroller