SwiftSky 1.3.2

SwiftSky 1.3.2

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jul 2017
SwiftSwift Version 3.1
SPMSupports SPM

Maintained by App Company.io.



SwiftSky 1.3.2

Documentation

SwiftSky let's you easily integrate the Dark Sky API into your Swift apps.

Requirements

Installation

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but SwiftSky does support its use on supported platforms.

Once you have your Swift package set up, adding SwiftSky as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .Package(url: "https://github.com/AppCompany/SwiftSky.git", majorVersion: 1)
]

Usage

Setup

First you must import SwiftSky everywhere you require to use it

import SwiftSky

Then before requesting any forecasts set the secret you got from darksky.net/dev/register

SwiftSky.secret = "<DARKSKY_SECRET>"

Settings

Optionally you can set the following settings as you wish (default values shown below)

SwiftSky.hourAmount = .fortyEight
        
SwiftSky.language = .english
    
SwiftSky.locale = .autoupdatingCurrent
    
SwiftSky.units.temperature = .fahrenheit
SwiftSky.units.distance = .mile
SwiftSky.units.speed = .milePerHour
SwiftSky.units.pressure = .millibar
SwiftSky.units.precipitation = .inch
SwiftSky.units.accumulation = .inch

For more details on these settings check the documentation

SwiftSky persists all your settings for you throughout a session. Simply set them once at app initialization and your good to go. You can change the settings anytime you want, though they will only be applied to new forecasts being requested.

Requesting a Forecast

There is one simple but versatile function for requesting forecasts SwiftSky.get(). The function requires you to specify what data you want for which location. The below example displays all possible data types there are. The location accepts a LocationConvertible meaning you can pass it a Location, CLLocation, CLLocationCoordinate2D or a String formatted as such: "<latitude>,<longitude>"

SwiftSky.get([.current, .minutes, .hours, .days, .alerts],
    at: Location(latitude: 1.1234, longitude: 1.234)
) { result in
    switch result {
    case .success(let forecast):
        // do something with forecast
    case .failure(let error):
        // do something with error
    }
}

Time Travel

Time travel requests are also possible simple give the SwiftSky.get function a Date like so:

SwiftSky.get([.hours],
    at: Location(latitude: 1.1234, longitude: 1.234),
    on: Date(timeIntervalSince1970: 0)
) { result in
    // handle like a regular forecast call
}

The Forecast Object

The details of the Forecast object and all the data it contains can be found here

Tests & Documentation

Documentation

This framework has been thoroughly tested and documented, as you can see by the badges above. A detailed description of the test coverage can be found here. The full documentation of SwiftSky can be found here

Contribute

As with every open-source project, contributions are always welcome!

However, please follow these rules:

  • Use the same style as is currently used
  • Write the appropriate documentation for it
  • Make sure everything is tested
  • The code must be 100% open-source

About

SwiftSky is developed and maintained by Luca Silverentand, owner of

App Company.io

Consider Donating

Are you using the framework and would like to see it being maintained and updated? Please consider helping me do exactly that by donating using the button below.

Donate