Search code examples
swiftxcodemigrationuikitswiftui

Replacing UIKit with SwiftUI in an existing project


I have an app that is currently made in UIKit, and I would like to fully migrate it to SwiftUI, removing all traces of UIKit.

I assume that replacing Main.storyboard and all of the ViewControllers with a SceneDelegate and ContentView won't be suffice for the migration.

What do I need to change in the project settings or overall to remove all traces of UIKit and replace it with SwiftUI? Is this even possible? Do I need to just create a new project and copy over all the custom settings?


Solution

  • Don't worry about "removing traces." Fun fact: Importing SwiftUI at the top of a file ALSO imports UIKit.

    What you said about the SceneDelegate and a UIHostingController is all you need actually. The only view controller you should ever need to load is the hosting controller. You literally just have a root view (ContentView or whatever) and start your whole app from that initial view. Be creative about your structure. Now is the time to experiment.