In the following Playground example, the UI updates with the current date correctly, however when navigating away from the page and coming back the timer does not resume ticking
Timer is canceled when there is no more subscribers, and when timer is cancelled it cannot be started again... so you need to make either not cancelling timer or recreate timer every time first tab is selected.
Here is possible solution (case 1, tested with Xcode 11.4)
struct MainTabView: View {
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
@State var time = Date()
var body: some View {
TabView {
VStack {
Text("\(time)")
}
.tabItem {
Text("Page 1")
}
Text("Page 2").tabItem {
Text("Page 2")
}
Text("Page 3").tabItem {
Text("Page 3")
}
}.onReceive(self.timer) { self.time = $0 } // here !!
}
}