How to combine two Dictionary instances in Swift?

前端 未结 10 1926
滥情空心
滥情空心 2020-12-01 04:13

How do I append one Dictionary to another Dictionary using Swift?

I am using the AlamoFire library to send a

10条回答
  •  再見小時候
    2020-12-01 04:33

    func += (lhs: inout [Key: Value], rhs: [Key: Value]) {
        rhs.forEach{ lhs[$0] = $1 }
    }
    
    var dic1 = ["test1": 1]
    
    dic1 += ["test2": 2]
    
    dic1  // ["test2": 2, "test1": 1]
    

提交回复
热议问题