A Swift library for the Forecast.io Dark Sky API

Overview

ForecastIO

Swift 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 (≥9.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 2.3

A Swift 2.3 compatible version of ForecastIO is available on the swift2.3 branch. This version is frozen at the ForecastIO 2.1.1 API and no longer supported. To install the Swift 2.3 compatible version of ForecastIO, simply add the following line to your Podfile:

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

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

github "sxg/ForecastIO" "swift2.3"

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 a DarkSkyClient with your API key:

import ForecastIO
...
let client = DarkSkyClient(apiKey: "YOUR_API_KEY_HERE")

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

client.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)

More details about the units of each property are available in the Dark Sky API docs.

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

client.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 DarkSkyClient, you can make two kinds of requests. The first will get the current Forecast for a particular location:

let myLoc = CLLocationCoordinate2D(latitude: myLat, longitude: myLon)
client.getForecast(location: myLoc) { result in
    switch result {
    case .success(let currentForecast, let requestMetadata):
        // We got the current forecast!
    case .failure(let 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:

let myLoc = CLLocationCoordinate2D(latitude: myLat, longitude: myLon)
client.getForecast(location: myLoc, time: myTime) { result in
    switch result {
    case .success(let forecast, let requestMetadata):
        // We got the forecast!
    case .failure(let 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 excludeFields parameter of the getForecast methods. excludeFields 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, [email protected], @_Satyam_

License

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

Comments
  • Nil Values

    Nil Values

    Ive noticed since updating to the latest version a lot of values are now nil all the time. All the precipitation values, temperatures low/high etc. Some data is being decoded but not all of it.

    bug 
    opened by Neilfau 5
  • Manually Installing without Pod

    Manually Installing without Pod

    Are there instructions on how to install all of the dependencies without using Pods?

    I am getting error:

    Library not loaded: @rpath/ForecastIO.framework/ForecastIO

    Thanks.

    opened by Sun3 4
  • Unexpected Error on all Forecast requests

    Unexpected Error on all Forecast requests

    This started yesterday. Has anyone else started seeing this? It seems like perhaps there was an API change or something? I'll keep investigating in the meantime.

    opened by Vortec4800 3
  • Receiving 'nil' for apiRequestsCount and responseTime

    Receiving 'nil' for apiRequestsCount and responseTime

    Everything about the API and ForecastIO is working well, except having trouble with getting the metadata for the apiRequestsCount and responseTime. Not sure if the issue is in my code, in ForecastIO, or in the DarkSky API

    My code:

    self.client.getForecast(latitude: lat, longitude: lon, excludeFields: [.alerts, .daily, .flags, .minutely]) { result in
                switch result {
                case .success(let currentForecast, let requestMetadata):
                    //  We got the current forecast!
                    if let currentFeelsTemperature: Double = currentForecast.currently?.temperature {
                        print(currentFeelsTemperature)
                        DispatchQueue.main.async {
                            self.feelsLikeTmpLbl.text = String(Int(round(currentFeelsTemperature)))
                        }
                    }
                    if let summaryInfo: String = currentForecast.currently?.summary {
                        print(summaryInfo)
                        DispatchQueue.main.async {
                            self.summaryLbl.text = summaryInfo
                        }
                    }
                    print(requestMetadata)
                case .failure(let error):
                    //  Uh-oh. We have an error!
                    print(error)
                }
            }
    

    Returns:

    RequestMetadata(cacheControl: Optional("max-age=3600"), apiRequestsCount: nil, responseTime: nil)
    
    opened by landesbergn 3
  • Forecast.swift: Unable to bridge NSNumber to Float.

    Forecast.swift: Unable to bridge NSNumber to Float.

    When the public init(fromJSON json: NSDictionary) (line 68) is called and it attempts to bridge the type NSNumber to Float, it causes a fatal error. I am running it with Swift 4 with iOS 11.3 and Xcode beta 9.3. Has anybody heard of this issue?

    opened by swiftdesginer0 3
  • Initialization Forecast.swift crash

    Initialization Forecast.swift crash

    We detected yesterday that the library was crashing few hours. After that, we didn't see the crash anymore.

    Crashed: NSOperationQueue 0x1740346c0 :: NSOperation 0x174c5d340 (QOS: DEFAULT) 0 ForecastIO 0x1012e710c specialized Forecast.init(fromJSON : NSDictionary) -> Forecast (Forecast.swift:69) 1 ForecastIO 0x1012dd2d0 specialized DarkSkyClient.(getForecast(url : URL, completionHandler : (Result) -> ()) -> ()).(closure #1) (Forecast.swift) 2 ForecastIO 0x1012dd084 partial apply for DarkSkyClient.(getForecast(url : URL, completionHandler : (Result) -> ()) -> ()).(closure #1) (DarkSkyClient.swift) 3 CFNetwork 0x18a7c934c __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 32 4 CFNetwork 0x18a7e1048 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 148 5 Foundation 0x18ac8e854 NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK + 16 6 Foundation 0x18abd37b0 -[NSBlockOperation main] + 96 7 Foundation 0x18abc3b68 -[__NSOperationInternal _start:] + 612 8 Foundation 0x18ac90bf0 __NSOQSchedule_f + 228 9 libdispatch.dylib 0x1890769a0 _dispatch_client_callout + 16 10 libdispatch.dylib 0x189084ad4 _dispatch_queue_serial_drain + 928 11 libdispatch.dylib 0x18907a2cc _dispatch_queue_invoke + 884 12 libdispatch.dylib 0x189086a50 _dispatch_root_queue_drain + 540 13 libdispatch.dylib 0x1890867d0 _dispatch_worker_thread3 + 124 14 libsystem_pthread.dylib 0x18927f100 _pthread_wqthread + 1096 15 libsystem_pthread.dylib 0x18927ecac start_wqthread + 4

    opened by MarcosMunoz 3
  • Exit Code 66

    Exit Code 66

    Receiving this error after running 'carthage update' I've also seen other resolved issues in the carthage repo that require you to remove the CarthageKit folder from Library/Cache but I've already tried that.

    Cartfile: github "sxg/ForecastIO" "swift3"

    A shell task (/usr/bin/xcrun xcodebuild -workspace /Users/tylermrolfe/Developer/Fake Name/Carthage/Checkouts/ForecastIO/ForecastIO.xcworkspace -scheme "Pods-ForecastIO OS X Tests-ForecastIO" -configuration Release CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean -showBuildSettings) failed with exit code 66:
    xcodebuild: error: Scheme Pods-ForecastIO OS X Tests-ForecastIO is not currently configured for the clean action.
    
    opened by tylermrolfe 3
  • Added a new call method

    Added a new call method

    Hey there great work on the API Client. I was messing around with Forecast API before and wanted to add on to your repo. There are two new main things added, one is way to exclude any data block that is not needed and another is extension on the hourly giving 168 hours of data instead of just 48 hours.

    opened by Abstract45 3
  • Unable to bridge NSNumber to Float Swift 3.3

    Unable to bridge NSNumber to Float Swift 3.3

    In Swift 3.3 .
    sometime got error ,because Unable to bridge NSNumber to Float Swift 3.3.

    latitude = json["latitude"] as! Float

    you should fix like this

    opened by V1ki 2
  • Crash in alert parsing when there is no

    Crash in alert parsing when there is no "expires" defined

    I'm getting a crash at line 35 in Alert.swift

    The code assumes that the "expires" property is required, but the documentation says its an optional.

    expires optional The UNIX time at which the alert will expire. (Some alerts sources, unfortunately, do not define expiration time, and in these cases this parameter will not be defined.)

    https://darksky.net/dev/docs/response

    There is currently an alert with no "expire" property at Whistler, but because alerts are temporary in nature, the I'm sure the repro won't last: https://api.darksky.net/forecast/[key]/50.1149639,-122.9486474

    "alerts": [ { "title": "Snowfall Warning", "regions": [ "Sunshine Coast" ], "severity": "warning", "time": 1486412460, "description": "Bands of snow rotating around a low pressure system off the coast will continue to stream across southern Vancouver Island, the Sunshine Coast and the Lower Mainland today. Snowfall amounts across these regions will vary widely depending on the location and intensity of the individual bands. Local amounts of 5 cm or more are likely. Be prepared to adjust your driving with changing road conditions. Visibility may be suddenly reduced at times in heavy snow. Please continue to monitor alerts and forecasts issued by Environment Canada. To report severe weather, send an email to [email protected] or tweet reports to #BCStorm.", "uri": "https://weather.gc.ca/warnings/report_e.html?bc38" } ]

    opened by katylinn 2
  • Module file was created by an older version of the compiler

    Module file was created by an older version of the compiler

    Hello,

    I'm getting following error as I installed ForecastIO pod:

    /---/---/ForecastViewController.swift:10:8: Module file was created by an older version of the compiler; rebuild 'ForecastIO' and try again: /---/---/Library/Developer/Xcode/DerivedData/SwiftyWeather-fcvyupiaiunpivcfwaqvzlakstdf/Build/Products/Debug-iphonesimulator/ForecastIO.framework/Modules/ForecastIO.swiftmodule/x86_64.swiftmodule

    Any clue?

    opened by HassanSE 2
Owner
Satyam Ghodasara
Resident physician and startup founder but a coder at heart.
Satyam Ghodasara
An Elegant Spotify Web API Library Written in Swift for iOS and macOS

Written in Swift 4.2 Spartan is a lightweight, elegant, and easy to use Spotify Web API wrapper library for iOS and macOS written in Swift 3. Under th

Dalton Hinterscher 107 Nov 8, 2022
A stable, mature and comprehensive Objective-C library for Twitter REST API 1.1

STTwitter A stable, mature and comprehensive Objective-C library for Twitter REST API 1.1 Like a FOSS version of Twitter Fabric TwitterKit, without th

Nicolas Seriot 1k Nov 30, 2022
Unified API Library for: Cloud Storage, Social Log-In, Social Interaction, Payment, Email, SMS, POIs, Video & Messaging.

Unified API Library for: Cloud Storage, Social Log-In, Social Interaction, Payment, Email, SMS, POIs, Video & Messaging. Included services are Dropbox, Google Drive, OneDrive, OneDrive for Business, Box, Egnyte, PayPal, Stripe, Google Places, Foursquare, Yelp, YouTube, Vimeo, Twitch, Facebook Messenger, Telegram, Line, Viber, Facebook, GitHub, Google+, LinkedIn, Slack, Twitter, Windows Live, Yahoo, Mailjet, Sendgrid, Twilio, Nexmo, Twizo.

CloudRail 195 Nov 29, 2021
Wanikani-swift - Unofficial Swift client for the WaniKani API

WaniKani A Swift library and client for the WaniKani REST API. It currently supp

Aaron Sky 5 Oct 28, 2022
A Swift wrapper for Foursquare API. iOS and OSX.

Das Quadrat Das Quadrat is Foursquare API wrapper written in Swift. Features Supports iOS and OSX. Covers all API endpoints. Authorization process imp

Constantine Fry 171 Jun 18, 2022
Unofficial GitHub API client in Swift

Github.swift ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut

Khoa 184 Nov 25, 2022
A swift SDK for Medium's OAuth2 API

Medium SDK - Swift A library to allow access to Medium API for any Swift iOS application. Features Medium.com authorization & token handling Login sta

null 11 Jan 22, 2022
Swift Wrapper For Bittrex API

BittrexApiKit Swift client for Bittrex api. It support all APIs with most recent changes. more info here let api = Bittrex(apikey: "api key", secretke

Saeid 8 Apr 5, 2021
Instagram API client written in Swift

SwiftInstagram is a wrapper for the Instagram API written in Swift. It allows you to authenticate users and request data from Instagram effortlessly.

Ander Goig 579 Dec 31, 2022
A Slack API Client for the Perfect Server-Side Swift Framework

PerfectSlackAPIClient is an API Client to access the Slack API from your Perfect Server Side Swift application. It is build on top of PerfectAPIClient

Cap.雪ノ下八幡 2 Dec 1, 2019
Questrade API written in Swift.

QuestradeAPI Getting Started The QuestAPI is made up of two main concepts: ResponseProviders API ResponseProviders The job of the provider is to retur

Eli Slade 2 Mar 15, 2022
Endless-Api-OP - A swift server for Endless

Endless-Api Introduce Hear is endless-api open source library. Endless-Api is us

Underthestars-zhy 1 Jan 30, 2022
The best way to use the Zora API in your Swift projects.

ZoraKit The best way to use the Zora API in your Swift projects. Disclaimer This is still very much a work in progress, and is really a proof-of-conce

MBLA 6 Sep 23, 2022
Twitter API for Cocoa developers

FHSTwitterEngine Twitter API for Cocoa developers Created by Nathaniel Symer FHSTwitterEngine can: Authenticate using OAuth and/or xAuth. Make a reque

Nathaniel Symer 213 Jul 8, 2022
Giphy API client for iOS in Objective-C

Giphy-iOS Giphy-iOS is a Giphy API client for iOS in Objective-C. Usage To run the example project, clone the repo, and run pod install from the Examp

alex choi 52 Jul 11, 2019
An easy-to-use Objective-C wrapper for the Uber API (no longer supported)

UberKit UberKit is a simple Objective-C wrapper for the new Uber API . Installation Cocoapods UberKit is available through Cocoapods. To install it, s

Sachin Kesiraju 95 Jun 30, 2022
Unofficial Dribbble iOS wrapper allows you to integrate Dribble API into iOS application (Designer, Shot, Comment, User Story, Like, Follow)

DribbbleSDK DribbbleSDK is easy-to-use iOS wrapper for Dribbble SDK. We're working hard to complete the full coverage of available methods and make th

Agilie Team 74 Dec 2, 2020
ObjectiveFlickr, a Flickr API framework for Objective-C

ObjectiveFlickr ObjectiveFlickr is a Flickr API framework designed for Mac and iPhone apps. OAuth Support ObjectiveFlickr now supports Flickr's new OA

Lukhnos Liu 714 Jan 9, 2023
Easy and powerful way to interact with VK API for iOS and macOS

Easy and powerful way to interact with VK API for iOS and macOS. Key features ?? It's not ios-vk-sdk ?? ?? One library for iOS and mac OS ?? ?? Fully

null 260 Dec 22, 2022