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
44
HabitTracker/Views/HabitRowView.swift
Normal file
44
HabitTracker/Views/HabitRowView.swift
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import SwiftUI
|
||||
import SwiftData
|
||||
|
||||
struct HabitRowView: View {
|
||||
@Environment(\.modelContext) private var context
|
||||
@Bindable var habit: Habit
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 12) {
|
||||
Image(systemName: habit.symbolName)
|
||||
.font(.title2)
|
||||
.foregroundStyle(Color(hex: habit.colorHex))
|
||||
.frame(width: 32)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(habit.name)
|
||||
.font(.headline)
|
||||
if habit.currentStreak > 0 {
|
||||
Text(streakText)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Button {
|
||||
context.toggleCompletion(for: habit, on: .now)
|
||||
} label: {
|
||||
Image(systemName: habit.isCompletedToday ? "checkmark.circle.fill" : "circle")
|
||||
.font(.title)
|
||||
.foregroundStyle(habit.isCompletedToday ? Color(hex: habit.colorHex) : Color.secondary)
|
||||
}
|
||||
.buttonStyle(.borderless)
|
||||
}
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
|
||||
private var streakText: String {
|
||||
let days = habit.currentStreak
|
||||
let unit = days == 1 ? "Tag" : "Tage"
|
||||
return "\(days) \(unit) Streak 🔥"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue