For a SwiftUI macOS App, I came up with this solution to enter full screen. In my use case I want the app to go full screen immediately on launch, but you can do this at any point.
import SwiftUI
@main
struct MacApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onAppear {
DispatchQueue.main.asyncAfter(0.1) {
if let window = NSApplication.shared.windows.last {
window.toggleFullScreen(nil)
}
}
}
}
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: