Latest 0.1.0
Homepage https://github.com/jmhdevelop/DecodeJSON
License MIT
Platforms ios 9.3
Authors

Status
Version
License
Platform
Swift
codebeat badge

Example

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

Installation

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

pod 'DecodeJSON'

Usage

First you need to create a struct for the response.

struct BookResponse: Codable {
    let ID: Int
    let Title: String
    let Description: String
    let PageCount: Int
}

Also you can created the struct with coding keys to assigning your own names.

struct BookResponse: Codable {
    let id: Int
    let title: String
    let description: String
    let numberOfPages: Int

    enum CodingKeys : String, CodingKey {
        case id = "ID"
        case title = "Title"
        case description = "Description"
        case numberOfPages = "PageCount"
    }
}

To decode a JSON in a request you can do it like in this example.

let url = URL(string: "https://fakerestapi.azurewebsites.net/api/Books")!

let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
    guard let data = data else { return }
        if let books: [BookResponse] = DecodeJSON.shared.decode(data: data) {
            print(books)
    }
}

task.resume()

Author

jmhdevep, [email protected]

License

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

Latest podspec

{
    "name": "DecodeJSON",
    "version": "0.1.0",
    "summary": "Simple way to decode a JSON",
    "homepage": "https://github.com/jmhdevelop/DecodeJSON",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "jmhdevep": "[email protected]"
    },
    "source": {
        "git": "https://github.com/jmhdevelop/DecodeJSON.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "9.3"
    },
    "swift_version": "4.2",
    "source_files": "DecodeJSON/Classes/**/*"
}

Pin It on Pinterest

Share This