Skip to content

vinhnx/DictionaryNestedSubscript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DictionaryNestedSubscript

A Swift Package that enable nested subscript on Dictionary.

Usage

import DictionaryNestedSubscript

let dictionary: [String: Any] = [
    "countries": [
        "japan": [
            "capital": [
                "name": "tokyo",
                "lat": "35.6895",
                "lon": "139.6917"
            ],
            "language": "japanese"
        ]
    ]
]

dictionary[jsonDict: "countries"]?[jsonDict: "japan"]?[jsonDict: "capital"]?["name"] // "tokyo"

Integration (requires Xcode 11+)

  1. from your project, Choose Xcode > File > Swift Packages > Add Package Dependency...

demo

  1. put https://github.com/vinhnx/DictionaryNestedSubscript under Choose Package Repository field

demo

  1. (optional) specify the version or branch or specific commit you want to use from the package

demo

  1. then click Next for Xcode to resolve the package.

demo

  1. Choose where to add Package framework to your app's target

demo

  1. Profit 😄

demo

References

Guide

Inspiration