📦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
Was this helpful?