SwiftUI: What are the differences between Image and UIImage?

Viewed 1184

I realize they are different structs, but when should one be used over another?

2 Answers

UIImage is a UIKit element it's created to be assigned to an UIImageView

Image is a SwiftUI element in the new framework released in IOS 13

You should avoid using UIKit elemnts in SwiftUI as possible , it's like using objective c code in swift which doesn't make sense of releasing a new language

To be more precise, Image is a struct meant to be used with SwiftUI, and UIImage is a class meant to be used with UIKit. If you are programming in SwiftUI, you want to be using Image, unless there is some missing functionality, in which case you might need to wrap a UIImage in a UIViewRepresentable.

Related