Skip to content

iOS Dictionary Utilities for Swift - allowing you to pull properties from a dictionary using a string eg. data.readString("field[0].name")

License

Notifications You must be signed in to change notification settings

willpowell8/DictionaryUtils

Repository files navigation

alt text

DictionaryUtils

Dictionary utils allows you to use JSON like referencing to travers an object.

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

DictionaryUtils is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "DictionaryUtils"

Usage

Lets say we define an aribitary dictionary that has an arrry within it. We ideally want to be able to access properties without referencing each child object, but in a more friendly fashion.

let data = ["data":["ary":[["value":1,"property1":"WELCOME"],["value":0,"property1":"WELCOME2"]]]]

We can find the property of a child by using the the following code

do {
    let output = try data.readString("data.ary[0].property1")
    print(output!)
}catch{
    print("ERROR")
}

This library will also let you do parameter based discovery within arrays like the below example:

do {
    let output = try data.readString("data.ary[value=0].property1")
    print(output!)
}catch{
    print("ERROR")
}

Author

willpowell8

License

DictionaryUtils is available under the MIT license. See the LICENSE file for more info.

About

iOS Dictionary Utilities for Swift - allowing you to pull properties from a dictionary using a string eg. data.readString("field[0].name")

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published