Search code examples
iosswiftobjective-cswiftui

Change Objective-C rootViewController to SwiftUI


I have a project built with React Native where for some feature I change the rootViewController from React Native to a Storyboard with the following code:

- (void) goToNativeView
{
  UIViewController *vc = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil].instantiateInitialViewController;
  self.window.rootViewController = vc;
  [self.window makeKeyAndVisible];
}

We want to get rid of Storyboard and use SwiftUI instead, but I wasn't able to find a way of doing the same thing we do with Storyboard but with SwiftUI

I want to know if it's possible and, if it is, how to do it


Solution

  • You need to use UIHostingController instead of UIViewController.

    https://developer.apple.com/documentation/swiftui/uihostingcontroller