Skip to content

Instantly share code, notes, and snippets.

View mich-adams's full-sized avatar
🧟‍♂️
like zoinks, scoob

Michael Adams mich-adams

🧟‍♂️
like zoinks, scoob
View GitHub Profile
@mich-adams
mich-adams / Streak.swift
Created April 28, 2022 16:33
Track user's exercise streak
public func updateStreak(recentExerciseMinutes: TimeInterval) {
@AppStorage("dog.currentStreak") var currentStreak: Int?
@AppStorage("dog.goal") var goal: Int?
@AppStorage("dog.todaysExercise") var todaysExercise: Int?
@AppStorage("dog.awardedDate") var awardedDate: Double? // Date stored as TimeInterval since 1970
@AppStorage("dog.lastExerciseDate") var lastExerciseDate: Double? // Date stored as TimeInterval since 1970
guard todaysExercise != nil else {
todaysExercise = 0
return