Files
Reflect/Shared/Models/WeatherData.swift
Trey t 31fb2a7fe2 Add weather feature with WeatherKit integration for mood entries
Fetch and display weather data (temp, condition, hi/lo, humidity) when
users log a mood. Weather is stored as JSON on MoodEntryModel and shown
as a card in EntryDetailView. Premium-gated with location permission
prompt. Includes BGTask retry for failed fetches and full analytics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 00:16:26 -05:00

33 lines
1009 B
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// WeatherData.swift
// Reflect
//
// Codable weather model stored as JSON string in MoodEntryModel.
//
import Foundation
struct WeatherData: Codable {
let conditionSymbol: String // SF Symbol from WeatherKit (e.g. "cloud.sun.fill")
let condition: String // "Partly Cloudy"
let temperature: Double // Current/average in Celsius
let highTemperature: Double // Day high in Celsius
let lowTemperature: Double // Day low in Celsius
let humidity: Double // 0.01.0
let latitude: Double
let longitude: Double
let fetchedAt: Date
// MARK: - JSON Helpers
func encode() -> String? {
guard let data = try? JSONEncoder().encode(self) else { return nil }
return String(data: data, encoding: .utf8)
}
static func decode(from json: String) -> WeatherData? {
guard let data = json.data(using: .utf8) else { return nil }
return try? JSONDecoder().decode(WeatherData.self, from: data)
}
}