Here is the same code in Swift Playground format:
//import Cocoa
//import Foundation
import WeatherKit
import CoreLocation
var token = [String]()
let escapedCity = "41.736,-88.095"
token = escapedCity.components(separatedBy: ",")
let weatherService = WeatherService()
let lat = Double(token[0])!
let long = Double(token[1])!
let thisLocation = CLLocation(latitude: lat, longitude: long)
let now = Calendar.current.date(byAdding: .hour, value: 1, to: Date())!
let nextWeek = Calendar.current.date(byAdding: .day, value: 14, to: Date())!
do
{
let (dailyForecast, hourlyForecast, currentWeather, alertWeather) =
try await weatherService.weather(for: thisLocation, including: .daily, .hourly(startDate: now, endDate: nextWeek), .current, .alerts)
print(String(format: "%.0f", currentWeather.temperature.converted(to: .fahrenheit).value))
print(String(format: "%.0f", hourlyForecast.count))
print(String(format: "%.0f", dailyForecast.count))
print(String(format: "%.0f", alertWeather?.count ?? 0))
}
catch
{
print(String(format:" Weather try/catch1 error: %@", error.localizedDescription))
print(String(format:" Weather full service not available: %.3f,%.3f", lat, long))
}
And returns the message:
remoteProcessWasInterrupted