'Error 'cannot find type 'UIHostingController' in scope'

Why could a distribution build be failed with SwiftUI?

I added SwiftUI into my iOS 10+ project, and build it locally with @available(iOS 13.0, *) prefix, but when I try to build the project for distribution, the build is failed with the following error:

cannot find type 'UIHostingController' in scope

The same error appears for other SwifUI types in my project (Text, View, Font, etc).



Solution 1:[1]

The UIHostingController type is provided by SwiftUI, not UIKit, so most likely, you need to add import SwiftUI to the top of your view controller source file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1