Last active
November 3, 2015 18:57
-
-
Save ericdke/2498b400a42e53cf6e2a to your computer and use it in GitHub Desktop.
Make a Dictionary from two arrays
This file contains hidden or 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 CollectionType where Generator.Element: Hashable { | |
| func dictionaryWithValues<U>(values: [U]) -> [Generator.Element:U] { | |
| var dict: [Generator.Element:U] = [:] | |
| zip(self, values).forEach { (k, v) in dict[k] = v } | |
| return dict | |
| } | |
| } | |
| let result = ["name", "age"].dictionaryWithValues(["eric", 42]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment