Git Product home page Git Product logo

wxkdarksky's Introduction

WXKDarkSky

This Swift package is a Decodable layer over the Dark Sky API for quick and easy access to API response objects. It’s super straightforward and modeled after the Dark Sky API docs. We use it in WeatherKit 2, and we thought others might find it helpful.

To be clear, this library strictly handles the coding of JSON data from Dark Sky into Swift structs. You’ll need to handle networking and all that on your own. (And of course, be sure to credit Dark Sky.)

Getting started

First, you’ll need to be using Swift 4. This code makes use of the Codable protocols, so the new version is a necessity. This also assumes some level of familiarity with Swift Package Manager.

Swift Package Manager

Of course, you'll need to add this package as a dependency in Swift Package Manager.

For Swift 4's Package Manager tools:

.package(url: "https://github.com/loopwxservices/WXKDarkSky.git", .exact("1.0.1"))

Be sure to add "WXKDarkSky" as a dependency in the targets section, too.

Carthage

Carthage is currently not officially supported as an installation medium. We’re not saying it’s impossible because it likely isn’t, but we don’t officially support it (yet).

CocoaPods

CocoaPods, like Carthage, is also not officially supported for installation at this time. If interest warrants, we’ll be happy to add support.

Manual

Just get the "WXKDarkSky.swift" file out of the Sources folder and drag it into your Xcode project. We don’t foresee massive changes to the Dark Sky API (or therefore this code) in the near future, so you shouldn’t have to come back here often.

Usage

Usage of WXKDarkSky is much like any JSON decoding in Swift 4:

let decoder = JSONDecoder()
let response = try! decoder.decode(WXKDarkSkyResponse.self, from: Data)

// Sample to get the current temperature
if let currently = response.currently {
    if let temperature = currently.temperature {
        print("Current temperature: "+temperature.description)
    }
}

The WXKDarkSkyResponse object structure perfectly matches that of the documented response format for ease of reference. In keeping with the documentation, nearly everything is an optional value, even if it is frequently included. No assumption is made about the availability of data.

If the API changes and we haven’t gotten around to updating WXKDarkSky yet, feel free to open an issue or a pull request and we’ll handle it promptly.

License

This package is licensed under the MIT License, which allows you to do just about anything with this Swift package (within Dark Sky's rules, of course) but sue us for any malfunctions. We hope someone finds it useful.

wxkdarksky's People

Contributors

jonblatho avatar

Watchers

OvanBiervliet avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.