Member-only story
Using SwiftUI Views with UIKit
Callbacks too!
Before we start
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 12.5, and Swift 5.4
Prerequisites:
- You’ll need to either be able to write an iOS application or write some Swift code in Playgrounds
The opportunity
We can use SwiftUI views and view controllers in our existing UIKit applications. This can be useful, since there is a feeling (and it might only be a feeling) that many resources and development are moving towards UIKit
. It might make sense to start your migration early, and begin to think about how you can make your code SwiftUI
compatible.
The warning
SwiftUI can only be used with iOS13 and up. This means that you would need to drop support for iOS12 devices — and this is something perhaps you are not willing to do for a production App.
One solution for this can be the following: