---
title: "withElements(_:)"
framework: realitykit
role: symbol
role_heading: Instance Method
path: "realitykit/perclothvertexdata/withelements(_:)"
---

# withElements(_:)

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

## Declaration

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

## Parameters

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

## Return Value

Return Value The value returned by callback.

## Discussion

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

## See Also

### Accessing vertex data

- [vertexCount](realitykit/perclothvertexdata/vertexcount.md)
- [mutableElements](realitykit/perclothvertexdata/mutableelements.md)
- [withMutableElements(_:)](realitykit/perclothvertexdata/withmutableelements(_:).md)
