Get your own website
Demo.swift
ContentView.swift
App.swift
 
import Foundation

let docs = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let file = docs.appendingPathComponent("hello.txt")

// Write text
let text = "Hello files!"
try? text.write(to: file, atomically: true, encoding: .utf8)

// Read text
let loaded = try? String(contentsOf: file, encoding: .utf8)
print(loaded ?? "")

                    
import SwiftUI

struct ContentView: View {
  @State private var result = ""
  var body: some View {
    VStack(spacing: 12) {
      Text("Write/Read demo executed. See console output.")
    }
    .padding()
  }
}

                    
import SwiftUI

@main
struct MyApp: App {
  var body: some Scene {
    WindowGroup { ContentView() }
  }
}