SwiftUI Image has no member 'resizable'

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?

Answered by BabyJ in 736786022

It seems like Image is being interpreted as a UIImage instead of a SwiftUI.Image.

Maybe you have something like this in your code:

typealias Image = UIImage

Has anyone been able to solve this?

My app was running without an issue, and I started getting this issue, the only fix I have found is to start a fresh project.

Please disregard the previous reply. I found the issue with my code.

I created an entity in CoreData with the name Image following some of the examples on the web and this created a conflict with the Image() function.

Maybe you had the same issue.

Accepted Answer

It seems like Image is being interpreted as a UIImage instead of a SwiftUI.Image.

Maybe you have something like this in your code:

typealias Image = UIImage

I am facing a same issue in my project, have you found a solution to this?

SwiftUI Image has no member 'resizable'
 
 
Q