Hello,
I am trying to add a SwiftUI view in a UIKit project but my SwiftUI code doesn’t compile.
import SwiftUI
@available(iOS 13.0.0, *)
struct SUITestView: View {
var body: some View {
Image(systemName: "square.and.pencil")
.resizable() // ❌ Value of type 'Image?' (aka 'Optional<UIImage>') has no member 'resizable'
}
}
@available(iOS 13.0.0, *)
struct SUITestView_Previews: PreviewProvider {
static var previews: some View {
SUITestView()
}
}
It looks like my compiler thinks I am using Swift code (UIImage) and not a SwiftUI Image.
My project configuration is a bit particular: Xcode 13.4.1, deploy target iOS 11.0, conditional use of SwiftUI with @available keyword.
I am still able to write SwiftUI code if I use only “Text” component, and I can display it using a UIHostingController. The problem is very specific to the “Image” component.
Has anyone already encountered this problem?