Skip to content

Instantly share code, notes, and snippets.

@SebastianBoldt
Created February 3, 2022 15:29
Show Gist options
  • Save SebastianBoldt/141f13816fa9003f37f51bdd290855c9 to your computer and use it in GitHub Desktop.
Save SebastianBoldt/141f13816fa9003f37f51bdd290855c9 to your computer and use it in GitHub Desktop.
struct ContentView: View {
private let formatter = {
let formatter = DateFormatter()
formatter.dateStyle = .none
formatter.timeStyle = .medium
return formatter
}()
private let timerSequence = Timer.publish(every: 1,
tolerance: 1,
on: .main,
in: .common)
.autoconnect()
.values
@State private var text: String = ""
var body: some View {
Text(text).task {
for await value in timerSequence {
text = formatter.string(from: value)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment