One Logo Pool Ball
SwiftUICore · IOS API REFERENCE

AnyShape

struct · iOS 16.0+ · SDK 27.1

@frozen struct 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 { OtherView().clipShape(isCircular ? AnyShape(Circle()) : AnyShape(Capsule())) } }

Members (5)

method · iOS 16.0+

sizeThatFits

TypeScript
sizeThatFits(proposal: ProposedViewSize): { width: number; height: number }
Swift declaration
nonisolated func sizeThatFits(_ proposal: ProposedViewSize) -> CGSize

Returns the size of the view that will render the shape, given a proposed size. Implement this method to tell the container of the shape how much space the shape needs to render itself, given a size proposal. See ``Layout/sizeThatFits(proposal:subviews:cache:)`` for more details about how the layout system chooses the size of views. - Parameters: - proposal: A size proposal for the container. - Returns: A size that indicates how much space the shape needs.

get · iOS 16.0+

animatableData

TypeScript
get animatableData(): AnyShape_AnimatableData
Swift declaration
nonisolated var animatableData: AnyShape.AnimatableData { get set }

The data to animate. SwiftUI reads this property to capture the current vector representation of the animatable state, and writes it back on each animation frame with an interpolated value. The default implementation returns ``EmptyAnimatableData``, meaning nothing is animated. Use the ``Animatable()`` macro to synthesize this property automatically. Implement it by hand only when you need custom interpolation logic such as clamping, normalization, or mapping to a derived value.

set · iOS 16.0+

animatableData

TypeScript
set animatableData(value: AnyShape_AnimatableData)
Swift declaration
nonisolated var animatableData: AnyShape.AnimatableData { get set }

The data to animate. SwiftUI reads this property to capture the current vector representation of the animatable state, and writes it back on each animation frame with an interpolated value. The default implementation returns ``EmptyAnimatableData``, meaning nothing is animated. Use the ``Animatable()`` macro to synthesize this property automatically. Implement it by hand only when you need custom interpolation logic such as clamping, normalization, or mapping to a derived value.

method · iOS 16.0+

path

TypeScript
path(rect: { x: number; y: number; width: number; height: number }): Path
Swift declaration
nonisolated func path(in rect: CGRect) -> Path

Describes this shape as a path within a rectangular frame of reference. - Parameter rect: The frame of reference for describing this shape. - Returns: A path that describes this shape.

init · iOS 16.0+

init

TypeScript
static init(shape: SDKHandle): AnyShape
Swift declaration
init<S>(_ shape: S) where S : Shape

Create an any shape instance from a shape.

Skipped declarations

No declarations were skipped in this snapshot.

All SwiftUICore types →