- 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.
推薦閱讀
- Word 2010中文版完全自學(xué)手冊
- 工業(yè)大數(shù)據(jù)分析算法實戰(zhàn)
- 大數(shù)據(jù):從概念到運營
- Spark核心技術(shù)與高級應(yīng)用
- 大數(shù)據(jù)時代下的智能轉(zhuǎn)型進(jìn)程精選(套裝共10冊)
- 軟件成本度量國家標(biāo)準(zhǔn)實施指南:理論、方法與實踐
- Python金融實戰(zhàn)
- 計算機(jī)應(yīng)用基礎(chǔ)教程上機(jī)指導(dǎo)與習(xí)題集(微課版)
- 聯(lián)動Oracle:設(shè)計思想、架構(gòu)實現(xiàn)與AWR報告
- 數(shù)據(jù)修復(fù)技術(shù)與典型實例實戰(zhàn)詳解(第2版)
- Internet of Things with Python
- Microsoft Dynamics NAV 2015 Professional Reporting
- 大數(shù)據(jù)計算系統(tǒng)原理、技術(shù)與應(yīng)用
- Kafka權(quán)威指南(第2版)
- 創(chuàng)新求索錄:第二集(精裝版)