56 lines
1.6 KiB
Swift
56 lines
1.6 KiB
Swift
//
|
|
// Defaults.swift
|
|
// WorkoutsPlus
|
|
//
|
|
// Created by Felix Förtsch on 04.09.24.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
|
|
public class Defaults: ObservableObject {
|
|
@AppStorage("isDebug") public var isDebug = true
|
|
|
|
@AppStorage("isFirstAppStart") public var isFirstAppStart = true
|
|
@AppStorage("isOnboarding") public var isOnboarding = true
|
|
@AppStorage("isTrainerMode") public var isTrainerMode = false
|
|
@AppStorage("isWorkingOut") public var isWorkingOut = false
|
|
|
|
@AppStorage("userId") public var userId = UUID().uuidString
|
|
@AppStorage("defaultWorkoutId") public var defaultWorkoutId: String = ""
|
|
|
|
@AppStorage("sets") public var sets = 8
|
|
@AppStorage("reps") public var reps = 8
|
|
|
|
// TODO: Maybe store session and workout ids to recover from app close
|
|
// @AppStorage("activeWorkoutSessionId") public var activeWorkoutSessionId: String = ""
|
|
// @AppStorage("activeWorkoutId") public var activeWorkoutId: String = ""
|
|
|
|
public static let shared = Defaults()
|
|
}
|
|
|
|
@propertyWrapper
|
|
public struct Default<T>: DynamicProperty {
|
|
@ObservedObject private var defaults: Defaults
|
|
private let keyPath: ReferenceWritableKeyPath<Defaults, T>
|
|
|
|
public init(_ keyPath: ReferenceWritableKeyPath<Defaults, T>, defaults: Defaults = .shared) {
|
|
self.keyPath = keyPath
|
|
self.defaults = defaults
|
|
}
|
|
|
|
public var wrappedValue: T {
|
|
get { defaults[keyPath: keyPath] }
|
|
nonmutating set { defaults[keyPath: keyPath] = newValue }
|
|
}
|
|
|
|
public var projectedValue: Binding<T> {
|
|
Binding(
|
|
get: { defaults[keyPath: keyPath] },
|
|
set: { value in
|
|
defaults[keyPath: keyPath] = value
|
|
}
|
|
)
|
|
}
|
|
}
|