https://github.com/vinhnx/dictionarynestedsubscript
Nested subscript for Dictionary.
https://github.com/vinhnx/dictionarynestedsubscript
demo github-package-registry smile swift swift-package-manager swiftpm xcode
Last synced: 7 months ago
JSON representation
Nested subscript for Dictionary.
- Host: GitHub
- URL: https://github.com/vinhnx/dictionarynestedsubscript
- Owner: vinhnx
- License: mit
- Created: 2019-06-11T05:43:12.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-04-17T13:45:49.000Z (almost 6 years ago)
- Last Synced: 2025-04-13T08:03:54.252Z (11 months ago)
- Topics: demo, github-package-registry, smile, swift, swift-package-manager, swiftpm, xcode
- Language: Swift
- Homepage:
- Size: 110 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DictionaryNestedSubscript
A Swift Package that enable nested `subscript` on `Dictionary`.
### Usage
```swift
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...`

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

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

4. then click `Next` for Xcode to resolve the package.

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

6. Profit :smile:

### References
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 :smile:)
+ https://stackoverflow.com/a/41543070/1477298 (for the logic :rocket:)