Created
March 31, 2018 06:14
-
-
Save anitaa1990/e8f1e3403749e0d0eb79111915b3906c to your computer and use it in GitHub Desktop.
A Swift extension class for Dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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