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

# forEach(_:)

Calls the given closure with an index and element of the array in the same order as a for-in loop.

## Declaration

```swift
func forEach(_ body: (Int, xpc_object_t) throws -> Void) rethrows
```

## Parameters

- `body`: A closure that takes an index and an element of the sequence as parameters.

## See Also

### Iterating over an array’s elements

- [forEach(_:)](xpc/xpcarray/foreach(_:)-6obs3.md)
