Created
February 3, 2022 15:29
-
-
Save SebastianBoldt/141f13816fa9003f37f51bdd290855c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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