Creates a new dictionary whose keys are the groupings returned by the given closure and whose values are arrays of the elements that returned each key.
- Xcode 10.2+
- Swift Standard Library
A sequence of values to group into a dictionary.
A closure that returns a key for each element in
The arrays in the “values” position of the new dictionary each contain at least one element, with the elements in the same order as the source sequence.
The following example declares an array of names, and then creates a dictionary from that array by grouping the names by first letter:
students dictionary has three entries, with students’ names grouped by the keys