- 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.
推薦閱讀
- Microsoft SQL Server企業(yè)級平臺管理實(shí)踐
- 數(shù)據(jù)挖掘原理與實(shí)踐
- Python絕技:運(yùn)用Python成為頂級數(shù)據(jù)工程師
- Python廣告數(shù)據(jù)挖掘與分析實(shí)戰(zhàn)
- R數(shù)據(jù)科學(xué)實(shí)戰(zhàn):工具詳解與案例分析(鮮讀版)
- Enterprise Integration with WSO2 ESB
- 數(shù)亦有道:Python數(shù)據(jù)科學(xué)指南
- Python金融實(shí)戰(zhàn)
- ZeroMQ
- Solaris操作系統(tǒng)原理實(shí)驗(yàn)教程
- 區(qū)塊鏈技術(shù)應(yīng)用與實(shí)踐案例
- 計(jì)算機(jī)視覺
- 數(shù)據(jù)庫查詢優(yōu)化器的藝術(shù):原理解析與SQL性能優(yōu)化
- PostgreSQL高可用實(shí)戰(zhàn)
- 數(shù)據(jù)中心UPS系統(tǒng)運(yùn)維