3

I am working on a SwiftUI app that still has the Scene / App Delegate files and would like to migrate it to the new SwiftUI App Protocol.

Is this only a matter of deleting the Scene / App Delegate files, then adding my ContentView (Initial View in my case) to the @main struct???

Thank you!

@main
struct TestApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

1 Answers1

8

You need to follow these steps to migrate a SwiftUI application to the new App life cycle:

  1. Create a new App struct and add the @main annotation:
@main
struct TestApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
  1. Remove the @main annotation from AppDelegate.

  2. Remove Scene Configuration from Info.plist:

enter image description here

  1. (Optionally) Move AppDelegate/SceneDelegate methods:
  1. Now you can remove the AppDelegate and SceneDelegate classes from the project (first make sure the app is indeed working as expected).
pawello2222
  • 34,912
  • 15
  • 99
  • 151