Hello,
I am new to the Swift and the SwiftUI. I want to build a MacOS app for learning purpose. Looks like I am stuck, so looking for some help.
The code below does not execute the print statement. Why is the timer not working? What am I missing? Thanks in advance.
struct CustomView: View {
let timer = Timer.publish(every: 1, on: .current, in: .common).autoconnect()
private var nums: [String] = ["one", "two"]
var body: some View {
ForEach(nums, id: \.self) {num in
Text(num)
}
.onReceive(timer) { time in
// why is this not working?
print("time is \(time)")
}
}
}
@main struct Writer: App {
var body: some Scene {
MenuBarExtra("Writer util", systemImage: "pencil.line") {
CustomView()
}
.menuBarExtraStyle(.menu)
}
}