Git Product home page Git Product logo

owonecall's Introduction

SwiftUI OpenWeather One Call API library

One Call API 2.5 and One Call API 3.0

"Make just one API call and get all your essential weather data for a specific location with our new OpenWeather One Call API."

OWOneCall is a small Swift library to connect to the One Call API 2.5 and One Call API 3.0 and retrieve the chosen weather data. Made easy to use with SwiftUI.

Provides for current, forecast and historical weather data through a single function call.

Usage

Weather data from OpenWeather One Call API is accessed through the use of a OWProvider, with a single function getWeather, eg:

let weatherProvider = OWProvider(apiKey: "your key")  // default One Call API 2.5
@State var weather = OWResponse()
...

// using a binding
weatherProvider.getWeather(lat: 35.661991, lon: 139.762735, weather: $weather, options: OWOptions.current())
...
Text(weather.current?.weatherInfo() ?? "")

// or using the async style, eg with `.task {...}`
if let results = await weatherProvider.getWeather(lat: 35.661991, lon: 139.762735, options: OWOptions.dailyForecast(lang: lang)) {
        weather = results
}

// or using the callback style, eg with `.onAppear {...}`
weatherProvider.getWeather(lat: 35.661991, lon: 139.762735, options: OWOptions.current()) { response in
       if let theWeather = response {
          self.weather = theWeather
       }
}

See the following for example uses:

Options

Options available:

Create an options object such as this, to retrieve the current weather data:

let myOptions = OWOptions(excludeMode: [.daily, .hourly, .minutely], units: .metric, lang: "en")

Additional convenience options to retrieve current and forecast weather data:

  • OWOptions.current(lang: String = "en")
  • OWOptions.dailyForecast(lang: String = "en")
  • OWOptions.hourlyForecast(lang: String = "en")

Additional convenience options to retrieve past historical weather data:

  • OWHistOptions.yesterday(lang: String = "en")
  • OWHistOptions.daysAgo(day: Double, lang: String = "en")

Use the lang options parameter to chose the language of the results, default "en".

Installation

Include the files in the ./Sources/OWOneCall folder into your project or preferably use Swift Package Manager.

Swift Package Manager (SPM)

Create a Package.swift file for your project and add a dependency to:

dependencies: [
  .package(url: "https://github.com/workingDog/OWOneCall.git", from: "1.3.2")
]

Using Xcode

Select your project > Swift Packages > Add Package Dependency...
https://github.com/workingDog/OWOneCall.git

Then in your code:

import OWOneCall

References

Requirement

Requires a valid OpenWeather key, see:

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.