- Hands-On Design Patterns with Swift
- Florent Vilmart Giordano Scalzo Sergio De Simone
- 132字
- 2021-07-02 14:45:10
Dictionaries
Let's take a look at the definition of the Dictionary type:
public struct Dictionary<Key, Value> where Key : Hashable
In an array, you can only carry a single type of object, but there is no constraint on this type of object. Dictionaries can hold any Value, but the Key has to conform to the Hashable protocol. The reason is simple: in order to efficiently index a dictionary and compare two dictionary keys, Swift uses the hash value of the key, instead of the key itself. This also helps us to write a variety of dictionary types that can make our programs more expressive.
Many types conform to the Hashable protocol, and you can make your own types conform to this protocol if you need to create you own custom dictionary keys.
推薦閱讀
- Hands-On Data Structures and Algorithms with Rust
- 在你身邊為你設(shè)計(jì)Ⅲ:騰訊服務(wù)設(shè)計(jì)思維與實(shí)戰(zhàn)
- 數(shù)據(jù)分析實(shí)戰(zhàn):基于EXCEL和SPSS系列工具的實(shí)踐
- Learning JavaScriptMVC
- 區(qū)塊鏈通俗讀本
- 區(qū)塊鏈:看得見的信任
- 達(dá)夢(mèng)數(shù)據(jù)庫(kù)性能優(yōu)化
- 城市計(jì)算
- INSTANT Android Fragmentation Management How-to
- 區(qū)域云計(jì)算和大數(shù)據(jù)產(chǎn)業(yè)發(fā)展:浙江樣板
- 二進(jìn)制分析實(shí)戰(zhàn)
- 改變未來的九大算法
- Visual FoxPro數(shù)據(jù)庫(kù)技術(shù)基礎(chǔ)
- Discovering Business Intelligence Using MicroStrategy 9
- 產(chǎn)品經(jīng)理數(shù)據(jù)修煉30問