Package -

SwiftSky

License Platform Pod Version Carthage compatible Swift Package Manager Compatible Build Status Documentation Test Coverage Apps Using SwiftSky Twitter Gitter

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

Requirements

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.1.0+ is required to build SwiftSky

To integrate SwiftSky into your Xcode project using CocoaPods, specify it in your Podfile:

use_frameworks!

target '<Your Target Name>' do
    pod 'SwiftSky', '~> 1.3'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate SwiftSky into your Xcode project using Carthage, specify it in your Cartfile:

github "AppCompany/SwiftSky" ~> 1.3

Run carthage update to build the framework and drag the built SwiftSky.framework into your Xcode project.

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 Test Coverage

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

Github

link
Stars:

Advertisement