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: "", 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