As of Swift 2.0, Dictionary’s values property now returns a LazyMapCollection instead of a LazyBidirectionalCollection. The Array type knows how to initialise itself using this abstract collection type:

let colors = Array(colorsForColorSchemes.values)

Swift's type inference already knows that these values are UIColor objects, so no type casting is required, which is nice!

Answer from Stuart on Stack Overflow
People also ask

What is a dictionary in Swift?
A dictionary in Swift is a collection that stores associations between keys of the same type and values of the same type in an unordered manner. Each value is associated with a unique key, which acts as an identifier for that value within the dictionary.
🌐
dhiwise.com
dhiwise.com › post › navigating-key-value-pairs-with-the-swift-dictionary
Navigating Key-Value Pairs with the Swift Dictionary
Is there a dictionary in Swift?
Yes, Swift includes dictionary as a fundamental collection type. They are incredibly useful for storing key value pairs in a way that ensures fast access to the values you store.
🌐
dhiwise.com
dhiwise.com › post › navigating-key-value-pairs-with-the-swift-dictionary
Navigating Key-Value Pairs with the Swift Dictionary
How to create a Swift dictionary?
To create a Swift dictionary, you can use the dictionary literal syntax by specifying key value pairs within square brackets and separating keys from values with a colon. Here's an example: ```swift //Creating a dictionary var bookGenres: [String: String] = ["P001": "Fiction", "P002": "Non-fiction"] //Creating an empty dictionary var bookGenres1 = [String: String]() var bookGenres2: Dictionary = [:] ```
🌐
dhiwise.com
dhiwise.com › post › navigating-key-value-pairs-with-the-swift-dictionary
Navigating Key-Value Pairs with the Swift Dictionary
🌐
Programiz
programiz.com › swift-programming › dictionary
Swift Dictionary (With Examples)
In the above example, we have created a dictionary named studentID. Initially, the value associated with the key 112 is "Kyle". Now, notice the line, ... Here, we have changed the value associated with the key 112 to "Stan". In Swift, we can access the keys and values of a dictionary independently.
🌐
Codecademy
codecademy.com › learn › learn-swift › modules › learn-swift-dictionaries › cheatsheet
Learn Swift: Dictionaries Cheatsheet | Codecademy
Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store. ... To assign the value of a key-value pair to a variable, set the value of a variable to dictionaryName[keyValue].
🌐
Hacking with Swift
hackingwithswift.com › sixty › 2 › 6 › dictionary-default-values
Dictionary default values - a free Hacking with Swift tutorial
May 28, 2019 - We can fix this by giving the dictionary a default value of “Unknown”, so that when no ice cream is found for Charlotte we get back “Unknown” rather than nil:
🌐
TutorialsPoint
tutorialspoint.com › home › swift › swift dictionaries
Swift Dictionaries
April 4, 2015 - Dictionaries are used to store unordered lists of values of the same type. Swift puts strict checking which does not allow you to enter a wrong type in a dictionary even by mistake.
Find elsewhere
🌐
Hacking with Swift
hackingwithswift.com › quick-start › beginners › how-to-store-and-find-data-in-dictionaries
How to store and find data in dictionaries - a free Swift for Complete Beginners tutorial
October 25, 2021 - As you can see, we’re now being really clear: the name is Taylor Swift, the job is Singer, and the location is Nashville. Swift calls the strings on the left – name, job, and location – the keys to the dictionary, and the strings on the right ...
🌐
DhiWise
dhiwise.com › post › navigating-key-value-pairs-with-the-swift-dictionary
Navigating Key-Value Pairs with the Swift Dictionary
July 10, 2024 - Think of it as a real-life dictionary, where each word (key) has a corresponding definition (value). In Swift, both keys and values are stored in a collection with no defined ordering, making it an unordered collection.
🌐
Swift Forums
forums.swift.org › using swift
How to transform in Swift a dictionary of array values to a dictionary of keys by values - Using Swift - Swift Forums
February 20, 2020 - Example: From: ["Key1":[1,2,3], "Key2", [4,5,6]] To: ["Key1": 1, "Key1": 2, "Key1": 3, "Key2":4, "Key2": 5, "Key2": 6] · The keys of a Dictionary are unique (there cannot be more than one eg "Key1" key), that's one of the defining features ...
🌐
GitHub
github.com › swiftlang › swift-evolution › blob › main › proposals › 0154-dictionary-key-and-value-collections.md
swift-evolution/proposals/0154-dictionary-key-and-value-collections.md at main · swiftlang/swift-evolution
New collection types provide efficient key lookup and mutable access to dictionary values, allowing in-place updates and copy-on-write optimization of stored values. The addition of these new types impacts the standard library ABI, since we won't be able to use types aliases from the existing types for keys and values. Swift-evolution thread: [Proposal Draft] Provide Custom Collections for Dictionary Keys and Values
Author   swiftlang
🌐
Swift.org
docs.swift.org › swift-book › LanguageGuide › CollectionTypes.html
The Swift Programming Language: Redirect
This content has moved; redirecting to the new location · This page requires JavaScript. Please turn on JavaScript and refresh the page
🌐
Swift Forums
forums.swift.org › using swift
Array of dictionaries. Get the values of a specific key - Using Swift - Swift Forums
September 20, 2019 - var arrayDictionaries: [[String: Any]] = [["key1": 1.1, "key2": 2.1, "key3": "value3.1"], ["key1": "value1.2", "key2": "value2.2", "key3": "value3.3"]] How can I get all the values of a specific key? In this simplified code, how to print all the key3
🌐
Hacking with Swift
hackingwithswift.com › read › 0 › 7 › dictionaries
Dictionaries - a free Hacking with Swift tutorial
September 29, 2025 - var person = ["Taylor", "Alison", "Swift", "December", "taylorswift.com"] To read out that person's middle name, we'd use person[1], and to read out the month they were born we'd use person[3]. This has a few problems, not least that it's difficult to remember what index number is assigned to each value in the array! And what happens if the person has no middle name? Chances are all the other values would move down one place, causing chaos in your code. With dictionaries we can re-write this to be far more sensible, because rather than arbitrary numbers you get to read and write values using a key you specify.
🌐
GeeksforGeeks
geeksforgeeks.org › swift › swift-dictionary
Swift - Dictionary - GeeksforGeeks
July 6, 2022 - In swift, a dictionary is a collection of key-value pairs. We can use any type of data as a key and any type of data as a value. We can create a dictionary using the (key:value) syntax.
🌐
Swift Documentation
swiftinit.org › docs › swift › swift › dictionary
Dictionary · Swift 6.1 documentation
A dictionary is a type of hash table, providing fast access to the entries it contains. Each entry in the table is identified using its key, which is a hashable type such as a string or number. You use that key to retrieve the corresponding value, which can be any object.
🌐
Matteo Manferdini
matteomanferdini.com › home › blog › organizing data by key in swift dictionaries
Organizing Data by Key in Swift Dictionaries
June 22, 2023 - Swift dictionaries offer many practical methods and properties that allow us to count, access, and iterate over their contents. The isEmpty and count properties help determine whether a dictionary contains any elements and how many there are. The keys and values properties allow you to access keys and values as arrays, which you can then manipulate using any of the Array type methods.
🌐
Educative
educative.io › answers › how-to-get-all-keys-of-the-dictionary-in-swift
How to get all keys of the Dictionary in Swift
The Swift Dictionary’s keys property gets all the keys present. The keys property will return a collection only containing keys of the Dictionary. The order of keys in the returned collection is the same as the order of key-value pairs present in the Dictionary.