Latest0.2.1
Homepagehttps://github.com/roadmaptravel/EasyDictionary
LicenseMIT
Platformsios 8.0
Authors

CI Status
Version
License
Platform
Twitter

Example

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

Requirements

  • Swift 4.0

Installation

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

pod 'EasyDictionary'

Summary

This little helper provides some methods to get optional and non-optional values from your dictionary. This can be used anywhere, but we use it mostly to parse data from an endpoint into an object.

Features

  • [x] Generic way of getting types from a dictionary.
  • [x] Parse urls directly.
  • [x] Parse dates directly.
  • [x] Parse timezones from a date string. (of course since we build THE travel app ;-)
  • [ ] Any more requests?

Usage

Retrieve the data

import EasyDictionary

let dictionary: [String: Any] = [
    "anInteger": 42,
    "originDate": "2018-05-03T07:15:00+02:00",
    "notJustAnUrl": "https://www.getroadmap.com/"
]

/// Get the integer from the dictionary.
let answerToEverything: Int = try dictionary.required("anInteger") // 42
let answerToEverything: Int? = dictionary.optional("anInteger") // Optional(42)
let answerToEverything: Int = try dictionary.required("doesntExists") // throws error!!

/// Get the url from the dictionary.
let bestTravelApp: URL = try dictionary.requiredUrl("notJustAnUrl") // https://www.getroadmap.com/
let bestTravelApp: URL? = dictionary.optionalUrl("notJustAnUrl") // Optional(https://www.getroadmap.com/)
let bestTravelApp: URL = try dictionary.requiredUrl("doesntExists") // throws error!!

/// Get the date from the dictionary
let dateFormatter: DateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssz"

let originsDate: Date = try dictionary.requiredDate("originDate", dateFormatter: dateFormatter) // 1525324500
let originsDate: Date? = dictionary.optionalDate("originDate", dateFormatter: dateFormatter) // Optional(1525324500)
let originsDate: Date = try dictionary.requiredDate("doesntExists", dateFormatter: dateFormatter) // throws error!!

Author

Niels Koole, Roadmap (Twitter)

License

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

Latest podspec

{
    "name": "EasyDictionary",
    "version": "0.2.1",
    "summary": "Nothing special just a few helpers to get values from a dictionary.",
    "description": "This little helper provides some methods to get optional and non-optional values from your dictionary. This can be used anywhere, but we use it mostly to parse data from an endpoint into an object.",
    "homepage": "https://github.com/roadmaptravel/EasyDictionary",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Niels Koole": "[email protected]"
    },
    "source": {
        "git": "https://github.com/roadmaptravel/EasyDictionary.git",
        "tag": "0.2.1"
    },
    "social_media_url": "https://twitter.com/roadmaptravel",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "EasyDictionary/Classes/**/*",
    "swift_version": "4.0"
}

Pin It on Pinterest

Share This