Chapter 4: Integrating UIViewController into SwiftUI

Chapter 4 talks about how to transition from UIViewController’s to SwiftUI’s view by tapping a a push button. I wonder if we can go from SwiftUI’s view to a view controller by tapping a button like the following?

import SwiftUI
import UIKit

struct ContentView: View {
@State var goToViewController: Bool = false
var body: some View {
VStack {
Button(action: {
self.goToViewController.toggle()
}) {
Text(“Go to a view controller”)
}
}
}
}

I don’t see a good answer in the following stack overflow post.
Thanks.

I expect WWDC will show us simpler new ways to integrate SwiftUI and UIKit, and I’ll have to rewrite this chapter completely :smile:.

Your book actually shows us how. So I’ve asked you to delete this topic after raising a flag. Anyway… Thanks.

1 Like