fix repetitive save of WorkoutItem, add: Onboarding, Defaults, Settings, Trainer/Trainee skeletons, reorder files, remove all Bindable
This commit is contained in:
@@ -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
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user