Last active
October 4, 2018 19:22
-
-
Save Otbivnoe/e585692c2f9c38544739a5a8c1e9360a to your computer and use it in GitHub Desktop.
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
@dynamicMemberLookup | |
protocol DictionaryDynamicLookup { | |
associatedtype Key | |
associatedtype Value | |
subscript(key: Key) -> Value? { get } | |
} | |
extension DictionaryDynamicLookup where Key == String { | |
subscript(dynamicMember member: String) -> Value? { | |
return self[member] | |
} | |
} | |
extension Dictionary: DictionaryDynamicLookup {} | |
let dict: [String : Any] = [ | |
"name": "Nikita", | |
"age": 24 | |
] | |
print(dict.name) | |
print(dict.age) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment