fix repetitive save of WorkoutItem, add: Onboarding, Defaults, Settings, Trainer/Trainee skeletons, reorder files, remove all Bindable

This commit is contained in:
Felix Förtsch
2024-09-04 18:44:28 +02:00
parent 0905ea7d3f
commit d82d0cd9fa
25 changed files with 426 additions and 134 deletions
+45
View File
@@ -0,0 +1,45 @@
//
// Defaults.swift
// WorkoutsPlus
//
// Created by Felix Förtsch on 04.09.24.
//
import Foundation
import SwiftUI
public class Defaults: ObservableObject {
@AppStorage("isFirstAppStart") public var isFirstAppStart = true
@AppStorage("isOnboarding") public var isOnboarding = true
@AppStorage("userId") public var userId = UUID().uuidString
@AppStorage("sets") public var sets = 8
@AppStorage("reps") public var reps = 8
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
}
)
}
}