How to create Dictionary that can hold anything in Key? or all the possible type it capable to hold

前端 未结 8 2065
感动是毒
感动是毒 2020-12-05 04:13

I want to create a Dictionary that does not limit the key type (like NSDictionary)

So I tried

var dict = Dictionary

        
8条回答
  •  长情又很酷
    2020-12-05 04:30

    Swift 3 update

    You can now use AnyHashable which is a type-erased hashable value, created exactly for scenarios like this:

    var dict = Dictionary()

提交回复
热议问题