I assume you're using Xcode 11 GM
and macOS Mojave
or Catalina
.
Along with the changes in the plist
, you have to add UISceneSession
lifecycle functions in the application delegate.
func application(_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// The name must match the one in the Info.plist
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
}
Also, you need to make sure the window
is created correctly in the SceneDelegate
.
func scene(_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = scene as? UIWindowScene else {
return
}
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: ContentView())
self.window = window
window.makeKeyAndVisible()
}
where ContentView
is the main SwiftUI
view you want to display.
P.S. Make sure the plist
specifies $(PRODUCT_MODULE_NAME).SceneDelegate
as delegate class name, and the scene delegate is called SceneDelegate
Example:
If you're on Catalina
, you can turn on Previews
in the build settings for your target.
Build Options -> Enable Previews
Addendum I:
Make sure you remove the Storyboard key from the Info.Plist and that you're targeting iOS 13
.
Addendum II:
Clean Derived Data
, as many devs in the comments suggest.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…