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

# mapValues(_:)

Returns a new dictionary containing the keys of this dictionary with the
values transformed by the given closure.

```
func mapValues<T, E>(_ transform: (Value) throws(E) -> T) throws(E) -> Dictionary<Key, T> where E : Error
```

## Parameters

`transform`

A closure that transforms a value. `transform`
accepts each value of the dictionary as its parameter and returns a
transformed value of the same or of a different type.

## Return Value

A dictionary containing the keys and transformed values of
this dictionary.

## Discussion> Complexity: O(*n*), where *n* is the length of the dictionary.

---

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)