You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func getDocumentsDirectory() -> URL {
// find all possible documents directories for this user
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
// just send back the first one, which ought to be the only one
return paths[0]
}
To write some text/data to the documents directory... SwiftUI
Text("Hello World")
.onTapGesture {
let str = "Test Message"
let url = self.getDocumentsDirectory().appendingPathComponent("message.txt")
do {
try str.write(to: url, atomically: true, encoding: .utf8)
let input = try String(contentsOf: url)
print(input)
} catch {
print(error.localizedDescription)
}
}