Skip to content

Instantly share code, notes, and snippets.

@beccadax
Last active October 26, 2016 15:04
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 beccadax/2298deb32b0c14d3bde1dd4f174dc754 to your computer and use it in GitHub Desktop.
Save beccadax/2298deb32b0c14d3bde1dd4f174dc754 to your computer and use it in GitHub Desktop.
extension Dictionary {
subscript(digging first: Key, rest: AnyHashable...) -> Any? {
return self[digging: first, rest[0..<rest.endIndex]]
}
subscript(digging first: Key, rest: ArraySlice<AnyHashable>) -> Any? {
let v = self[first]
guard let firstOfRest = rest.first else {
return v
}
let dict = v as? [AnyHashable: Any]
return dict?[digging: firstOfRest, rest.dropFirst()]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment