A Swift Package that enable nested subscript
on Dictionary
.
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"
- from your project, Choose
Xcode > File > Swift Packages > Add Package Dependency...
- put
https://github.com/vinhnx/DictionaryNestedSubscript
underChoose Package Repository
field
- (optional) specify the version or branch or specific commit you want to use from the package
- then click
Next
for Xcode to resolve the package.
- Choose where to add Package framework to your app's target
- Profit 😄
Guide
- https://developer.apple.com/documentation/swift_packages/creating_a_swift_package_with_xcode
- https://developer.apple.com/documentation/swift_packages/publishing_a_swift_package_with_xcode
Inspiration
- https://github.com/krzyzanowskim/CollectionSafeIndex (for the idea 😄)
- https://stackoverflow.com/a/41543070/1477298 (for the logic 🚀)