user14542817
user14542817

Reputation:

How do you migrate to the new SwiftUI App Protocol?

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()
        }
    }
}

Upvotes: 13

Views: 4045

Answers (1)

pawello2222
pawello2222

Reputation: 54516

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).

  2. Reinstall the app (as suggested in the comments).

Upvotes: 24

Related Questions