Swift equivalent to `[NSDictionary initWithObjects: forKeys:]`

后端 未结 5 1414
别跟我提以往
别跟我提以往 2020-11-27 07:41

Is there an equivalent for Swift\'s native Dictionary to [NSDictionary initWithObjects: forKeys:]?

Say I have two arrays with keys and valu

5条回答
  •  伪装坚强ぢ
    2020-11-27 08:09

    You can simply use the Swift equivalent of initWithObjects:forKeys:

    let keys = ["one", "two", "three"]
    let values = [1, 2, 3]
    var dict = NSDictionary.init(objects: values, forKeys: keys)
    

提交回复
热议问题