📦AnyShape

SwiftUIshapesShape ⟩ AnyShape

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

Was this helpful?