Last active
          March 22, 2017 16:52 
        
      - 
      
- 
        Save JosephDuffy/31b462439357cc1716ed3eac3b98a6bb to your computer and use it in GitHub Desktop. 
  
    
      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
    
  
  
    
  | import Foundation | |
| extension Dictionary { | |
| subscript(keys: String...) -> Any? { | |
| var value: Any = self | |
| for key in keys { | |
| guard let dictionary = value as? [String: Any] else { return nil } | |
| guard let newValue = dictionary[key] else { return nil } | |
| value = newValue | |
| } | |
| return value | |
| } | |
| } | |
| let dict = [ | |
| "foo": [ | |
| "bar": [ | |
| "value": 1 | |
| ] | |
| ] | |
| ] | |
| dict["foo", "bar", "value"] // 1 | |
| dict["foo", "bar", "😱"] // nil | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment