<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "swift: 4.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Dictionary/filter(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SD6filterySDyxq_GSbx3key_q_5valuet_tqd__YKXEqd__YKs5ErrorRd__lF"
  },
  "title" : "filter(_:)"
}
-->

# filter(_:)

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

```
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

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

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)