Skip to content

Instantly share code, notes, and snippets.

@Otbivnoe
Created October 3, 2018 21:20
Show Gist options
  • Save Otbivnoe/26b469e02be213d15433cd6660aad665 to your computer and use it in GitHub Desktop.
Save Otbivnoe/26b469e02be213d15433cd6660aad665 to your computer and use it in GitHub Desktop.
@dynamicMemberLookup
struct Person {
subscript(dynamicMember member: String) -> String {
let properties = ["name": "Nikita", "age": "24"]
return properties[member, default: ""]
}
}
print(Person().name) // Nikita
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment