---
title: "filter(_:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/dictionary/filter(_:)"
---

# filter(_:)

Returns a new dictionary containing the key-value pairs of the dictionary that satisfy the given predicate.

## Declaration

```swift
consuming func filter<E>(_ isIncluded: (Dictionary<Key, Value>.Element) throws(E) -> Bool) throws(E) -> [Key : Value] where E : Error
```

## Parameters

- `isIncluded`: A closure that takes a key-value pair as its argument and returns a Boolean value indicating whether the pair should be included in the returned dictionary.

## Return Value

Return Value A dictionary of the key-value pairs that isIncluded allows.

## See Also

### Removing Keys and Values

- [removeValue(forKey:)](swift/dictionary/removevalue(forkey:).md)
- [remove(at:)](swift/dictionary/remove(at:).md)
- [removeAll(keepingCapacity:)](swift/dictionary/removeall(keepingcapacity:).md)
