Request OpenWeatherMap data with ease in Swift

What's New

Combine Publishers


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>


CodeFactor Github Actions GitHub license

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


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


Add .package(url: "https://github.com/henrik-dmg/HPOpenWeather", from: "3.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 OpenWeatherMap. 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
HPOpenWeather.shared.apiKey = "--- YOUR API KEY ---"

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 = TimeMachineRequest(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 the requestWeather on HPOpenWeather:

HPOpenWeather.shared.requestWeather(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


  • Current weather data
  • Daily and hourly forecast
  • More Unit Tests
  • Historical Data
  • UV Index Data
  • watchOS and tvOS demo apps

This documentation is far from complete, however the code itself is pretty well documented so feel free to just play around and just contact me if you have any suggestions :)


  • Swift Tools 5.1.0


Last updated: Thu Oct 15 2020 04:08:31 GMT-0500 (GMT-05:00)