Add property rawValue to State

Modify the wrapped value without updating the view
This commit is contained in:
david-swift 2024-01-02 08:01:40 +01:00
parent 8eb004c9ea
commit 26b46e3338
2 changed files with 18 additions and 4 deletions

View File

@ -13,6 +13,10 @@ Access the stored value. This updates the views when being changed.
Get the value as a binding using the `$` prefix.
### `rawValue`
Get and set the value without updating the views.
### `content`
The stored value.

View File

@ -11,18 +11,16 @@ import Foundation
@propertyWrapper
public struct State<Value>: StateProtocol {
// swiftlint:disable force_cast
/// Access the stored value. This updates the views when being changed.
public var wrappedValue: Value {
get {
content.storage.value as! Value
rawValue
}
nonmutating set {
content.storage.value = newValue
rawValue = newValue
Self.updateViews()
}
}
// swiftlint:enable force_cast
/// Get the value as a binding using the `$` prefix.
public var projectedValue: Binding<Value> {
@ -33,6 +31,18 @@ public struct State<Value>: StateProtocol {
}
}
// swiftlint:disable force_cast
/// Get and set the value without updating the views.
public var rawValue: Value {
get {
content.storage.value as! Value
}
nonmutating set {
content.storage.value = newValue
}
}
// swiftlint:enable force_cast
/// The stored value.
public let content: State<Any>.Content