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.
LaunchScreen.storyboard
, the screen becomes black – AlphonsoalphonsusSwiftUI
. I created an empty project with storyboard in Xcode 11 and decided to delete this storyboard and add view controllers manually. The mistake was I added this code in "app delegate" but should do the similar thing in "scene delegate". – Salve