---
title: "forEach(_:)"
framework: xpc
role: symbol
role_heading: Instance Method
path: "xpc/xpcdictionary/foreach(_:)-9hufx"
---

# forEach(_:)

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

## Declaration

```swift
func forEach(_ body: (XPCDictionary.KeyValuePair) throws -> Void) rethrows
```

## Parameters

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

## See Also

### Iterating over keys and values

- [forEach(_:)](xpc/xpcdictionary/foreach(_:)-6riqn.md)
