Skip to content

JSONContentManager is a library for retreiving values from json file given its keys path with the ability to pass custom values

License

Notifications You must be signed in to change notification settings

mhmdzaid/JSONContentManager

Repository files navigation

JSONContentManager

CI Status Version License Platform

Example

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

Requirements

swift version 5.0 , iOS 12

Installation

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

pod 'JSONContentManager'

How to use?

let's assume we have a json file like this :

{
"Employees": [
    {
        "name": "Joe",
        "role": "developer"
    },
    {
        "name": "wu jan",
        "role": "product owner"
    },
    {
        "name": "nicky",
        "role": "sales manager"
    }],

    "Product": {
        "name": "coffee machine",
        "specs": {
         "height": 40,
         "weight": "12kg"
        },
        "bill": "you paid {0} of {1}."
    }
}

First import JSONContentManager in your code

import JSONContentManager

Then create instance of JSONContentManager and pass json file name as a parameter

let contentManager = JSONContentManager.init(JSONFile: "ExampleJSONFile")

After that you can get value by passing its keys path like that :

let value = contentManager.value(from: "Product.specs.height") // value = 40 

Also you can add external values to the value by passing it as placeHolders as follows:

let value = contentManager.stringValue(from: "Product.bill",
                                                    placeholders: ["12.35$","40,30$"]) // you paid 12.35$ of 40,30$.

Author

mozead1996, [email protected]

License

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

About

JSONContentManager is a library for retreiving values from json file given its keys path with the ability to pass custom values

Resources

License

Stars

Watchers

Forks

Packages