'How can I return some InsettableShape Protocol in SwiftUI
I have a function which returns some InsettableShape like this:
func test(value: Int) -> some InsettableShape {
if (value == 0) {
return Circle()
}
else if (value == 1) {
return Capsule()
}
else {
return Rectangle()
}
}
Xcode give an error of:
Function declares an opaque return type, but the return statements in its body do not have matching underlying types
because there is a missing ShapeBuilder or InsettableShapeBuilder wrapper, I cannot make this code work, how can I solve this problem?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|