Swiftpack.co - Package - henrik-dmg/HPOpenWeather
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.


CodeFactor Github Actions GitHub license

HPOpenWeather is a cross-platform Swift framework to communicate with the OpenWeather One-Call API. See their documentation for further details.


HPOpenWeather supports iOS 9.0+, watchOS 3.0+, tvOS 9.0+ and macOS 10.10+.


Add .package(url: "https://github.com/henrik-dmg/HPOpenWeather", from: "4.0.0") to your Package.swift file


Add pod 'HPOpenWeather' to your Podfile and run pod install


To get started, you need an API key from OpenWeather. Put this API key in the initialiser, additionally you can also specify a custom temperature format and/or language used in the responses (see list for available languages and units below).

import HPOpenWeather

// Assign API key
OpenWeather.shared.apiKey = "--- YOUR API KEY ---"
OpenWeather.shared.language = .german
OpenWeather.shared.units = .metric

// Or use options
let settings = OpenWeather.Settings(apiKey: "yourAPIKey", language: .german, units: .metric)

You can also customise the response data units and language by accessing the language and units propertis.

Making a request

To make a request, initialize a new request object like this

let request = WeatherRequest(coordinate: .init(latitude: 40, longitude: 30))

Or to request weather data from the past:

let timemachineRequest = WeatherRequest(coordinate: .init(latitude: 40, longitude: 30), date: someDate)

Note: the date has to be at least 6 hours in the past

To post a request, call sendWeatherRequest on OpenWeather:

OpenWeather.shared.performWeatherRequest(request) { result in
	switch result {
    case .success(let response):
    	// do something with weather data here
    case .failure(let error):
        // handle error

The following response languages are available

  • English (default)
  • Russian
  • Italian
  • Spanish
  • Ukrainian
  • German
  • Portuguese
  • Romanian
  • Polish
  • Finnish
  • Dutch
  • French
  • Bulgarian
  • Swedish
  • Chinese Traditional
  • Chinese Simplified
  • Turkish
  • Croatian
  • Catalan

The following temperature units are available

  • Celsius (default)
  • Kelvin
  • Fahrenheit


Stars: 10


Version 4.0.0 - 2020-12-15T23:25:32

I've made some breaking changes, so my early Christmas present to you is version 4.0.0. Most notable changes:

  • Renamed HPOpenWeather to OpenWeather
  • Updated some method signatures
  • greatly simplified decoding of responses which improves readability
  • expanded documentation
  • added weather alerts

The Housekeeping Update - 2020-12-05T10:36:32

Changes in this version:

  • dependencies were updated, including some fixes to the completion handling of the networking stack
  • the completion is now called on the correct queue if the weather request could not be constructed

Combine Publishers - 2020-10-07T14:25:44

This release brings you Combine publishers for weather request and automatic response decoding. Here's an example:

let someCoordinate = CLLocationCoordinate2D(latitude: 42.989, longitude: -25.128)
let request = WeatherRequest(coordinate: someCoordinate)

let cancellable = request.makePublisher(apiKey: TestSecret.apiKey)

cancellable will be a publisher of type AnyPublisher<OpenWeatherRequest.Output, Error>

Support for custom URLSession - 2020-06-30T13:21:04

Support for specifying finishing queue - 2020-06-15T10:04:36

Also refactored towards global settings and not having to set language and API key on every request

Fix init is inaccessible due to internal protection level - 2020-05-05T16:39:00

This closes #4

- 2020-04-13T21:12:08

- 2020-04-09T23:31:37

- 2020-04-09T20:06:27

Made Icon Cache access thread-safe - 2019-05-01T19:57:01

Pre-Release of v2.0.0 - 2019-04-28T22:25:19

Ooh this is a big one. Version 2.0.0 completely revamps the framework from the ground up, because let's be honest it was pretty sucky before. I added cross-platform support so the library now runs on iOS 9.0+, watchOS 2.0+, tvOS 9.0+ and macOS 10.10+ so you can now build a weather app even for your Apple TV. The way you make a request is now also a lot more streamlined, just instantiate a WeatherRequest object and pass it to any API method you like (so you can reuse one request object on multiple occasions for example). I also got rid of any external dependencies so you have a nice, lightweight framework. Also, I discovered the Codableprotocol which basically turned my world upside down

Weekend well spent, cheers

Releasing updated Pod version - 2019-01-08T10:49:41

- 2017-02-12T14:25:44

Updated Pod - 2017-02-12T11:11:43

Podspec release - 2017-02-11T17:12:22