diff --git a/Sources/AppState/Application/Application+public.swift b/Sources/AppState/Application/Application+public.swift index 0072934..7577b7f 100644 --- a/Sources/AppState/Application/Application+public.swift +++ b/Sources/AppState/Application/Application+public.swift @@ -85,7 +85,7 @@ public extension Application { let dependency = shared.value(keyPath: keyPath) log( - debug: "🟢 Starting Dependency Override \(String(describing: keyPath))", + debug: "🟢 Starting Dependency Override \(String(describing: keyPath)) with \(value)", fileID: fileID, function: function, line: line, @@ -99,7 +99,7 @@ public extension Application { return DependencyOverride { log( - debug: "🟢 Cancelling Dependency Override \(String(describing: keyPath))", + debug: "🟢 Cancelling Dependency Override \(String(describing: keyPath)) ", fileID: fileID, function: function, line: line, @@ -146,15 +146,17 @@ public extension Application { _ line: Int = #line, _ column: Int = #column ) -> State { + let appState = shared.value(keyPath: keyPath) + log( - debug: "🔵 Getting State \(String(describing: keyPath))", + debug: "🔵 Getting State \(String(describing: keyPath)) -> \(appState.value)", fileID: fileID, function: function, line: line, column: column ) - return shared.value(keyPath: keyPath) + return appState } /** @@ -170,15 +172,17 @@ public extension Application { _ line: Int = #line, _ column: Int = #column ) -> StoredState { + let storedState = shared.value(keyPath: keyPath) + log( - debug: "🟣 Getting StoredState \(String(describing: keyPath))", + debug: "🟣 Getting StoredState \(String(describing: keyPath)) -> \(storedState.value)", fileID: fileID, function: function, line: line, column: column ) - return shared.value(keyPath: keyPath) + return storedState } // MARK: - Instance Methods @@ -298,4 +302,23 @@ public extension Application { scope: Scope(name: feature, id: id) ) } + + /** + Retrieves a `UserDefaults` backed state for the provided `id` with a default value of `nil`. + + - Parameters: + - feature: The name of the feature to which the state belongs, default is "App". + - id: The specific identifier for this state. + - Returns: The state of type `Value`. + */ + func storedState( + feature: String = "App", + id: String + ) -> StoredState { + storedState( + initial: nil, + feature: feature, + id: id + ) + } } diff --git a/Sources/AppState/Application/Application.swift b/Sources/AppState/Application/Application.swift index a6dccf8..5cc7e70 100644 --- a/Sources/AppState/Application/Application.swift +++ b/Sources/AppState/Application/Application.swift @@ -34,15 +34,14 @@ public class Application: ObservableObject { line: Int, column: Int ) { + guard isLoggingEnabled else { return } + let excludedFileIDs: [String] = [ "AppState/Application+StoredState.swift" ] let isFileIDValue: Bool = excludedFileIDs.contains(fileID.description) == false - guard - isLoggingEnabled, - isFileIDValue - else { return } + guard isFileIDValue else { return } let codeID = codeID(fileID: fileID, function: function, line: line, column: column) diff --git a/Sources/AppState/PropertyWrappers/AppState.swift b/Sources/AppState/PropertyWrappers/AppState.swift index e87d4e5..469b893 100644 --- a/Sources/AppState/PropertyWrappers/AppState.swift +++ b/Sources/AppState/PropertyWrappers/AppState.swift @@ -26,6 +26,14 @@ import SwiftUI ).value } nonmutating set { + Application.log( + debug: "🔵 Setting State \(String(describing: keyPath)) = \(newValue)", + fileID: fileID, + function: function, + line: line, + column: column + ) + var state = app.value(keyPath: keyPath) state.value = newValue } diff --git a/Sources/AppState/PropertyWrappers/StoredState.swift b/Sources/AppState/PropertyWrappers/StoredState.swift index cc5d4e7..7a042da 100644 --- a/Sources/AppState/PropertyWrappers/StoredState.swift +++ b/Sources/AppState/PropertyWrappers/StoredState.swift @@ -27,6 +27,14 @@ import SwiftUI ).value } nonmutating set { + Application.log( + debug: "🟣 Setting StoredState \(String(describing: keyPath)) = \(newValue)", + fileID: fileID, + function: function, + line: line, + column: column + ) + var state = app.value(keyPath: keyPath) state.value = newValue } diff --git a/Tests/AppStateTests/StoredStateTests.swift b/Tests/AppStateTests/StoredStateTests.swift index feb7f92..baafae5 100644 --- a/Tests/AppStateTests/StoredStateTests.swift +++ b/Tests/AppStateTests/StoredStateTests.swift @@ -4,7 +4,7 @@ import XCTest fileprivate extension Application { var storedValue: StoredState { - storedState(initial: nil, id: "storedValue") + storedState(id: "storedValue") } }