• How to use a timer with SwiftUI

      1. struct ContentView: View {
      2. @State var currentDate = Date()
      3. let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
      4. var body: some View {
      5. Text("\(currentDate)")
      6. .onReceive(timer) { input in
      7. currentDate = input
      8. }
      9. }
      10. }