How do I append one Dictionary
to another Dictionary
using Swift
?
I am using the AlamoFire
library to send a
SequenceType.forEach
(implemented by Dictionary
) provides an elegant solution to add a dictionary's elements to another dictionary.
dic1.forEach { dic2[$0] = $1 }
For example
func testMergeDictionaries() {
let dic1 = [1:"foo"]
var dic2 = [2:"bar"]
dic1.forEach { dic2[$0] = $1 }
XCTAssertEqual(dic2[1], "foo")
}