Skip to content

0.1.0

Latest

Choose a tag to compare

@0xLeif 0xLeif released this 04 Dec 00:27

SwiftWeather

macOS
Ubuntu
License
Version

Pre-1.0 Notice: This library is under active development. The API may change between minor versions until 1.0.

A Swift library for fetching weather data from multiple providers.

Features

  • Multiple Providers - NWS (US) and Open-Meteo (international)
  • Automatic Selection - Uses best provider based on location
  • Swift 6 Concurrency - Full async/await support
  • Cross-Platform - iOS, macOS, tvOS, watchOS, visionOS

Installation

Add SwiftWeather as a dependency in your Package.swift:

dependencies: [
    .package(url: "https://github.com/CorvidLabs/swift-weather.git", from: "0.1.0")
]

Then add the target dependency:

.target(
    name: "YourTarget",
    dependencies: [
        .product(name: "Weather", package: "swift-weather")
    ]
)

Quick Start

import Weather

let config = WeatherConfiguration(
    userAgent: "(MyApp, [email protected])"
)
let weather = Weather(configuration: config)

let current = try await weather.current(
    latitude: 47.6062,
    longitude: -122.3321
)

print("Temperature: \(current.temperature.fahrenheit)°F")
print("Condition: \(current.conditionDescription)")

Configuration

// US locations (uses NWS with Open-Meteo fallback)
let usConfig = WeatherConfiguration.us(userAgent: "(MyApp, [email protected])")

// International locations (uses Open-Meteo only)
let intlConfig = WeatherConfiguration.international(userAgent: "(MyApp, [email protected])")

// Custom configuration
let config = WeatherConfiguration(
    userAgent: "(MyApp, [email protected])",
    temperatureUnit: .celsius,
    providerStrategy: .automatic
)

Weather Conditions

The library supports these weather conditions:

  • clear - Clear skies
  • partlyCloudy - Partly cloudy
  • cloudy - Overcast
  • fog - Foggy conditions
  • drizzle - Light rain
  • rain - Rain
  • freezingRain - Freezing rain
  • snow - Snow
  • sleet - Sleet/ice pellets
  • thunderstorm - Thunderstorms
  • unknown - Unknown condition