TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Getting precipitation data from WeatherKit

Forums > SwiftUI

Hi!

I am using WeatherKit in my app and am trying to see how I can get precipitation data.

It appears to be an enum in the documentation : https://developer.apple.com/documentation/weatherkit/precipitation

var precipitation: String {
        let precipitation = minForecast?.precipitation.description
        return precipitation ?? "Loading Weather Data"
    }

However, I continue to get nil when trying to return from precipitation. I have an enum setup:

enum Precipitation:String {
        case hail
        case mixed
        case rain
        case snow
        case sleet
        case none
    }

Would I need to return Precipitation.precipitation?

2      

Hi, I was able to pull the precipitation using the 'rawValue' property.

let service = WeatherService()
let newYork = CLLocation(latitude: 40.730610, longitude: -73.935242)

do {
    let daily = try await service.weather(for: newYork, including: .daily)
    precipitation = daily.forecast[0].precipitation.rawValue
} catch let error {
    print(error)
}

There is no need to create the enum

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.