11

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

18

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

pawello2222
  • 46,897
  • 22
  • 145
  • 209
  • 7
    Also you need totally reinstall app from your device with clean up – Sound Blaster Dec 24 '21 at 23:08
  • 1
    You actually don't need to reinstall the app, at least on the simulator. You just need to completely close the app and restart – GBreen12 Sep 12 '22 at 16:11
  • 1
    @SoundBlaster you are such a life-saver. I was having a heart attack not understanding why after doing all of this, my app would launch as Catalyst target but not load the SwiftUI 'App' on iOS. – dinesharjani Nov 17 '22 at 15:49
  • @GBreen12 not sure about that. I just followed the steps exactly and was only getting a black screen on iOS until I removed and reinstalled the app. – pinglock Dec 09 '22 at 18:02