-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Term Entry] Swift dictionary.mapValues() #5212
[Term Entry] Swift dictionary.mapValues() #5212
Conversation
- 'paths/build-ios-apps-with-swiftui' | ||
--- | ||
|
||
In Swift, the `mapValues()` method is used to transform the values of a dictionary while keeping the keys unchanged. This method is part of the `Dictionary` structure and is useful for modifying or mapping only the values without altering the keys. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Swift, the `mapValues()` method is used to transform the values of a dictionary while keeping the keys unchanged. This method is part of the `Dictionary` structure and is useful for modifying or mapping only the values without altering the keys. | |
In Swift, the **`mapValues()`** method is used to transform the values of a dictionary while keeping the keys unchanged. This method is part of the [Dictionary](https://www.codecademy.com/resources/docs/swift/dictionaries) structure and is useful for modifying or mapping only the values without altering the keys. |
|
||
## Syntax | ||
|
||
```swift |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```swift | |
```pseudo |
The result of `mapValues()` is a new dictionary with the same keys, but the values are transformed based on the provided closure. | ||
|
||
> **Note:** `mapValues()` does not modify the original dictionary; instead, it returns a new dictionary with the transformed values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result of `mapValues()` is a new dictionary with the same keys, but the values are transformed based on the provided closure. | |
> **Note:** `mapValues()` does not modify the original dictionary; instead, it returns a new dictionary with the transformed values. | |
> **Note:** `mapValues()` does not modify the original dictionary but returns a new dictionary with the same keys and values that are transformed based on the provided closure. |
- `dictionaryName`: The instance of a `Dictionary` whose values you want to transform. | ||
- The `mapValues` method returns a new dictionary with the same keys, but with the values transformed based on the provided closure. | ||
- `transformation`: A closure that defines how each value in the dictionary should be transformed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `dictionaryName`: The instance of a `Dictionary` whose values you want to transform. | |
- The `mapValues` method returns a new dictionary with the same keys, but with the values transformed based on the provided closure. | |
- `transformation`: A closure that defines how each value in the dictionary should be transformed. | |
- `dictionaryName`: The instance of a `Dictionary` whose values are transformed. | |
- `mapValues`: The method returns a new dictionary with the same keys, but with the values transformed based on the provided closure. | |
- `transformation`: A closure that defines how each value in the dictionary should be transformed. |
- The `mapValues` method returns a new dictionary with the same keys, but with the values transformed based on the provided closure. | ||
- `transformation`: A closure that defines how each value in the dictionary should be transformed. | ||
|
||
The result of `mapValues()` is a new dictionary with the same keys, but the values are transformed based on the provided closure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result of `mapValues()` is a new dictionary with the same keys, but the values are transformed based on the provided closure. | |
The `mapValues()` function return a new dictionary with the same keys, but the values are transformed based on the provided closure. |
|
||
## Example | ||
|
||
In the following example, the `mapValues()` method is used to increase each student's grade by 10 points in the `studentGrades` dictionary: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the following example, the `mapValues()` method is used to increase each student's grade by 10 points in the `studentGrades` dictionary: | |
In the following example, the `mapValues()` method is used to increase each student's grade by `10` points while keeping the keys unchanged in the `studentGrades` dictionary: |
Hi @Great-Visions-Code thank you for contributing to Codecademy docs, I have suggested a few changes please modify them. |
Hi, @Great-Visions-Code thank you for contributing to Codecademy docs, I have suggested a few changes please modify them. |
@cigar-galaxy82 I have made the suggested changes. Please let me know if anything else is needed. Thank you, |
minor changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing @Great-Visions-Code 😄
The entry is ready to be merged! 🚀
prettified
👋 @Great-Visions-Code 🎉 Your contribution(s) can be seen here: https://www.codecademy.com/resources/docs/swift/dictionaries/mapValues Please note it may take a little while for changes to become visible. |
Description
Issue Solved
Type of Change
Checklist
main
branch.Issues Solved
section.