<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/PerClothVertexData/withElements(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:22RealityFoundationCloth03PerC10VertexDataV12withElementsyqd__qd__s4SpanVyxGXElF"
  },
  "title" : "withElements(_:)"
}
-->

# withElements(_:)

Provides read-only access to the per-vertex data within a callback.

```
func withElements<Result>(_ callback: (Span<ElementType>) -> Result) -> Result
```

## Parameters

`callback`

A closure that receives a span over the per-vertex data.

## Return Value

The value returned by `callback`.

## Discussion

The provided span is only valid for the lifetime of the callback.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)