For Catalyst, you can reach to your scene in .onAppear modifier, like so:
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onAppear { hideTitleBarOnCatalyst() }
}
}
func hideTitleBarOnCatalyst() {
#if targetEnvironment(macCatalyst)
(UIApplication.shared.connectedScenes.first as? UIWindowScene)?.titlebar?.titleVisibility = .hidden
#endif
}
}
And if needed, you still have access to the AppDelegate protocol:
import SwiftUI
@main
struct MyApp: App {
@UIApplicationDelegateAdaptor private var appDelegate: MyAppDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
class MyAppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
return true
}
}
More details here: https://developer.apple.com/documentation/swiftui/uiapplicationdelegateadaptor