In a SwiftUI macOS app that uses the SwiftUI App lifecycle I have been struggling to understand how to launch a new window and then assign it some initial state.
Using Xcode 12.5’s new project we get:
import SwiftUI
@main
struct StackOverflowExampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
To keep the question simple, let’s say that I would like to launch a new window every minute and send the time the window was launched to the view. For this we can use a Timer like so:
Timer.scheduledTimer(
withTimeInterval: 60,
repeats: true,
block: {_ in
// do something here that launches a new window containing
// ContentView and sends it the current time
}
)
Any ideas on how to proceed?