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

# mapValues(_:)

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

## Declaration

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

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

## Discussion

Discussion note: O(n), where n is the length of the dictionary.

## See Also

### Transforming a Dictionary

- [reduce(_:_:)](swift/dictionary/reduce(_:_:).md)
- [reduce(into:_:)](swift/dictionary/reduce(into:_:).md)
- [compactMap(_:)](swift/dictionary/compactmap(_:).md)
- [compactMapValues(_:)](swift/dictionary/compactmapvalues(_:).md)
- [flatMap(_:)](swift/dictionary/flatmap(_:)-i3ly.md)
- [flatMap(_:)](swift/dictionary/flatmap(_:)-6chv9.md)
- [sorted(by:)](swift/dictionary/sorted(by:).md)
- [shuffled()](swift/dictionary/shuffled().md)
- [shuffled(using:)](swift/dictionary/shuffled(using:).md)
