Skip to content

some View conform to UIView #234

@Skyline-23

Description

@Skyline-23

I use it with UIKit and preview
but when I use extension UIView preview, I got this error

Return type of instance method 'showPreview(width:height:)' requires that 'some View' conform to 'UIView'

This is my extension code

#if canImport(SwiftUI) && DEBUG
import SwiftUI
extension UIView {

    private struct Preview: UIViewRepresentable {
        let view: UIView

        func makeUIView(context: Context) -> UIView {
            return view
        }

        func updateUIView(_ uiView: UIView, context: Context) {
        }
    }

    func showPreview(width: CGFloat, height: CGFloat) -> some View {
        Preview(view: self).previewLayout(.fixed(width: width, height: height))      // error line
    }
}
#endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions