In my legacy code base with public Xcode 15.0, I can’t preview any UIKit views with the new #Preview macro
import SwiftUI
#Preview {
let uiView = UIView()
return uiView
}
The canvas fails to load preview with failure diagnostic
Compiling failed: return expression of type 'UIView' does not conform to 'View'
2
Answers
I can’t build too..
the same error: Compiling failed: return expression of type ‘UIButton’ does not conform to ‘View’
I find that restricting this one-statement preview to iOS 17 works:
However, this two-statement preview still does not work:
To get the two-statement preview to work, I have to make the variable type explicit: