ios-tracker/HabitTracker/Support/WidgetSync.swift
rene 22b8f5d806 Initiales HabitTracker-Projekt: SwiftUI + SwiftData Gewohnheiten-Tracker
Natives iOS-App-Gerüst (Xcode 26, synchronisierte Ordner, iOS 18+).

Features:
- Gewohnheiten anlegen (Name, SF-Symbol, Farbe), heute abhaken, Streaks, Löschen
- Detailansicht mit Monatskalender (Tage nachtragbar) und Statistiken
- Tägliche Erinnerungen via lokale Notifications
- Home-Screen-Widget (klein/mittel) mit App-Group-Datenaustausch
2026-05-29 21:12:45 +02:00

24 lines
791 B
Swift

import Foundation
import SwiftData
import WidgetKit
enum WidgetSync {
/// Writes the current habits to the shared store and reloads widget timelines.
static func refresh(_ context: ModelContext) {
let descriptor = FetchDescriptor<Habit>(sortBy: [SortDescriptor(\.createdAt)])
let habits = (try? context.fetch(descriptor)) ?? []
let items = habits.map { habit in
WidgetSnapshot.Item(
id: habit.uuid,
name: habit.name,
symbolName: habit.symbolName,
colorHex: habit.colorHex,
isDoneToday: habit.isCompletedToday
)
}
SharedStore.save(WidgetSnapshot(generatedAt: .now, items: items))
WidgetCenter.shared.reloadAllTimelines()
}
}