๐Ÿ“ฆAnyShape

SwiftUI โŸฉ shapes โŸฉ Shape โŸฉ AnyShape

A type-erased shape value. You can use this type to dynamically switch between shape types.

struct MyClippedView: View {

    var isCircular: Bool

    var body: some View {
        ClippedView()
            // โœ… OK (ๅฐ‡ Circle ่ˆ‡ Capsule ๅŒ–็‚บ AnyShape)
            .clipShape(isCircular ? AnyShape(Circle()) : AnyShape(Capsule()))
        ErrorView()
            // ๐Ÿž mismatching types (Circle, Capsule ็‚บไธๅŒ้กžๅž‹)
            .clipShape(isCircular ? Circle() : Capsule())
    }
}

Last updated