HomeiOS Developmentios - Adapting SwiftUI like circulate in UIKit/Storyboard primarily based app

ios – Adapting SwiftUI like circulate in UIKit/Storyboard primarily based app


I do not know if I am getting this proper, however sure, you possibly can load storyboard views or any UIViewController view doing one thing like this:

struct MyView: UIViewControllerRepresentable {
    func makeUIViewController(context: Context) -> MyViewController {
        // For Storyboard views
        let storyboard = UIStoryboard(title: "Most important", bundle: nil)
        let viewController = storyboard.instantiateViewController(withIdentifier: "MyViewController") as! MyViewController
        // For manually created UIViewControllers
        /*
        let vc = MyAwesomeViewController()
        return vc
        */
        return viewController
    }

    func updateUIViewController(_ uiViewController: MyViewController, context: Context) {
        // Replace the view controller right here
    }
}

Then you need to use the above code prefer it was a SwiftUI view:

struct ContentView: View {
    var physique: some View {
        MyView()
    }
}

Additionally, I do not know the way outdated is your app however it appears fairly latest to me, however it was frequent follow to make use of AppDelegate (and even earlier than SceneDelegate) in SwiftUI apps. If you wish to use an AppDelegate or your current one into your SwiftUI app you possibly can by declaring it into the struct that extends App in your SwiftUI challenge like this:

@UIApplicationDelegateAdaptor(MyAppDelegate.self) var appDelegate

And it ought to work prefer it was in a UIKit this manner.
I hope I used to be capable of at the very least enable you partially.
Have a pleasant coding day!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments