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

前端 未结 8 2052
感动是毒
感动是毒 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:24

    I believe that, as of Swift 1.2, you can use an ObjectIdentifier struct for this. It implements Hashable (and hence Equatable) as well as Comparable. You can use it to wrap any class instance. I'm guessing the implementation uses the wrapped object's underlying address for the hashValue, as well as within the == operator.

提交回复
热议问题