Skip to content

sxg/ForecastIO

 
 

Repository files navigation

ForecastIO

CI Status Documentation Carthage compatible Version License Platform

Requirements

To use ForecastIO, all you need is an API key for the Dark Sky API. ForecastIO supports iOS (≥8.0), macOS (≥10.10), watchOS (≥2.0), and tvOS (≥9.0).

Installation

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

pod "ForecastIO"

To integrate using Carthage, specify it in your Cartfile:

github "sxg/ForecastIO"

Swift 3

A pre-release version of ForecastIO with Swift 3 compatibility is available on the swift3 branch. To install it, simply add the following line to your Podfile:

pod "ForecastIO", :git => "https://github.com/sxg/ForecastIO.git", :branch => "swift3"

To integrate the Swift 3 compatible version using Carthage, specify it in your Cartfile:

github "sxg/ForecastIO" "swift3"

Documentation & Unit Tests

The full documentation for ForecastIO is available on CocoaDocs.

ForecastIO includes a full suite of unit tests with 100% code coverage.

Usage

First, create an APIClient with your API key:

import ForecastIO
...
let forecastIOClient = APIClient(apiKey: "YOUR_API_KEY_HERE")

You can choose units that you want Forecast responses to use:

forecastIOClient.units = .SI

The following units are supported:

  • SI
  • US (default)
  • Canadian
  • UK
  • Auto (uses the local units for the location for which you are requesting weather data)

You can also choose the language that you want Forecast responses to use:

forecastIOClient.language = .English

Many languages are supported (a full list is available here). If no language is specified, English is used as the default.

With the APIClient, you can make two kinds of requests. The first will get the current Forecast for a particular location:

forecastIOClient.getForecast(latitude: myLat, longitude: myLon) { (currentForecast, error) -> Void in
  if let currentForecast = currentForecast {
    //  We got the current forecast!
  } else if let error = error {
    //  Uh-oh we have an error!
  }
}

The second kind of request is called a time machine request, and it will get a Forecast for a particular location at a particular time:

forecastIOClient.getForecast(latitude: myLat, longitude: myLon, time: myTime) { (forecast, error) -> Void in
  if let forecast = forecast {
    //  We got the forecast!
  } else if let error = error {
    //  Uh-oh we have an error!
  }
}

The Forecast you receive will have metadata as well as DataPoints and DataBlocks associated with it. A DataPoint such as the currently property on Forecast represents various weather phenomena occurring at a specific instant in time. A DataBlock such as the minutely, hourly, and daily properties on Forecast represent the various weather phenomena occurring over a period of time and are represented by an array of DataPoints.

DataPoints and DataBlocks contain a large amount of information, and any of these fields can be excluded from the API response through the excludeForecastFields parameter of the getForecast methods. excludeForecastFields is optional and defaults to an empty array, meaning no data will be excluded from the API response. Alternatively, if you need more data, you can set the extendHourly parameter of the getForecast method to true to make the hourly property on Forecast return hourly data for a full week instead of 24 hours. extendHourly is an optional parameter and defaults to false. extendHourly is not supported on time machine requests.

For a full list of properties defined on all models, consult the full documentation on CocoaDocs.

Author

Satyam Ghodasara, sghodas@gmail.com

License

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

About

A Swift library for the Forecast.io Dark Sky API

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 7