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
This commit is contained in:
commit
22b8f5d806
24 changed files with 1448 additions and 0 deletions
24
HabitTracker/Support/WidgetSync.swift
Normal file
24
HabitTracker/Support/WidgetSync.swift
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
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()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue