Hi, need some help with an iOS application we are trying to make future safe. Basically, we know that our app would require SwiftUI so the app is made in that framework, however we require some important elements that are available only in UIKit, so we've made a bridge that allows us to pass UIKit views to SwiftUI to display them. So most of the app actually has UI made in UIKit, however, we now need to use the Charts framework present in SwiftUI, we've used SwiftUI buttons in our UIKit before by passing them through a HostingController (Passing SwiftUI buttons to UIKit to use). And we are currently considering to the same for SwiftUI Charts. Just to recap, it's a SwiftUI iOS app, that is mostly made in UIKit (through a bridge) but also has other SwiftUI elements injected into it. What we want to know that, is this the best way to do this? Or is there a better way to have UIKit and SwiftUI work more comfortably with eachother. The reason for such looping around is also because we interoping our C++ code to Swift for making this application, since we are making it for many other platforms and the business logic is in C++. Let me know if there are better ways to go about this!
Help with SwiftUI and UIKit Interjection
Hi @vipulgupta012 ,
great question!
Are you showing your UIKit views with UIViewControllerRepresentable
and then passing your SwiftUI views in here with a UIHostingController
?
Here's an article, yes I know it's for visionOS but it pertains exactly to this question. https://developer.apple.com/documentation/visionos/bringing-your-app-to-visionos#Consider-your-implementation
The linked portion is about using SwiftUI and UIKit together. You can disregard the visionOS specific piece.
Let me know if this helps!