Swiftpack.co -  Package - henrik-dmg/HPOpenWeather
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
henrik-dmg/HPOpenWeather
Request OpenWeather data with ease in Swift
.package(url: "https://github.com/henrik-dmg/HPOpenWeather.git", from: "4.1.4")

Storage

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.

Installation

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

SPM

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

CocoaPods

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

Usage

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)
OpenWeather.shared.apply(settings)

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

GitHub

link
Stars: 11
Last commit: 3 weeks ago

Release Notes

Version 4.0.0
16 weeks ago

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

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco