DEV Community

Working with your UIViewController and SwiftUI

Maarek on June 11, 2019

So you started playing with SwiftUI, and you enjoyed it ? Well, me too! The second it came out, I started to imagine all the use cases I'll enjoy i...
Collapse
 
jpelayo profile image
jpelayo • Edited

Almost there with my test, but the original ViewController lacks something, as the compiler cries:

Protocol 'View' requirement '_makeView(view:inputs:)' cannot be satisfied by a non-final class ('ViewController') because it uses 'Self' in a non-parameter, non-result type position

Can you point me to the "non-final class" fundamentals?

Thanks for the pathway!

PS: Adding "final" to the class declaration compiles, but no view is rendered

Collapse
 
kevinmaarek profile image
Maarek

Can you provide some of your SwiftUI code ?

Collapse
 
jpelayo profile image
jpelayo • Edited

Thanks... but... solved!

Thing is that you can also do:


 func makeUIViewController(context: UIViewControllerRepresentableContext<MyView>) -> ViewController {


        return UIStoryboard(name: "MyViewControllerStoryboard", bundle: nil).instantiateViewController(identifier: String(describing: ViewController.self)) as! ViewController

    }

Cheers!

Collapse
 
utkarshshekhar profile image
Utkarsh Shekhar

I have a project of pattern lock built in UIKit and I want to import it into my SwiftUI project as a View in full page. So my question is how will I get the UI as it is build in Storyboard?
Is it possible to achieve that using UIViewController ?

Github Repo Pattern Lock => github.com/Tinghui/HUIPatternLockV...

Thank You.

Collapse
 
steveblue profile image
Stephen Belovarich

I'm guessing the same is true of NSViewControllerRepresentable?

Collapse
 
kevinmaarek profile image
Maarek

Exactly!