Skip to content

Instantly share code, notes, and snippets.

@anitaa1990
Created March 31, 2018 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anitaa1990/e8f1e3403749e0d0eb79111915b3906c to your computer and use it in GitHub Desktop.
Save anitaa1990/e8f1e3403749e0d0eb79111915b3906c to your computer and use it in GitHub Desktop.
A Swift extension class for Dictionary
extension Dictionary {
/*
* merge two dictionaries together to a single dictionary
* var data1: Dictionary<String, String> = ["Fname", "Anitaa"]
* var data2: Dictionary<String, String> = ["lname", "Murthy"]
* var data3: data1.update(data2)
* print(data3) -> ["Fname": "Anitaa", "lname" : "Murthy"]
*/
mutating func update(other:Dictionary) {
for (key,value) in other {
self.updateValue(value, forKey:key)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment