TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jul 2017 |
SwiftSwift Version | 3.1 |
SPMSupports SPM | ✓ |
Maintained by App Company.io.
SwiftSky let's you easily integrate the Dark Sky API into your Swift apps.
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)
]
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>"
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.
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 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 details of the Forecast
object and all the data it contains can be found here
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
As with every open-source project, contributions are always welcome!
However, please follow these rules:
SwiftSky is developed and maintained by Luca Silverentand, owner of
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.