---
title: "forEach(_:)"
framework: xpc
role: symbol
role_heading: Instance Method
path: "xpc/xpcarray/foreach(_:)-6obs3"
---

# forEach(_:)

Calls the given closure with each element in the array in the same order as a for-in loop.

## Declaration

```swift
func forEach(_ body: (XPCArray.IndexValuePair) throws -> Void) rethrows
```

## Parameters

- `body`: A closure that takes an element of the array as a parameter.

## See Also

### Iterating over an array’s elements

- [forEach(_:)](xpc/xpcarray/foreach(_:)-2ib8a.md)
