Request OpenWeather data with ease in Swift

What's New

Concurrency support


This release adds support for Swift 5.5 new concurrency features as well as some new properties for the weather responses


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 13.0+, watchOS 7.0+, tvOS 13.0+ and macOS 10.15+.


Add .package(url: "https://github.com/henrik-dmg/HPOpenWeather", from: "5.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:

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

// Or using the new concurrency features
let response = try await OpenWeather.shared.weatherResponse(request)

Available languages (default in bold)

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

Available units (default in bold)

  • Metric (wind speed in m/s, temperature in Celsius)
  • Imperial (wind speed in mph, temperature in Fahrenheit)
  • Standard (wind speed in m/s, temperature in Kelvin)


  • Swift Tools 5.5.0
View More Packages from this Author


Last updated: Tue Jan 17 2023 05:51:09 GMT-0500 (GMT-05:00)