Created
April 27, 2023 05:58
-
-
Save DavidBemerguy/5b2b46738ff30c616d78bc97b8b1cacd to your computer and use it in GitHub Desktop.
Property wrapper that keeps versioning of the property - Very useful for debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@propertyWrapper | |
struct Versioned<Value> { | |
private var currentValue: Value | |
private(set) var history: [Value] = [] | |
init(wrappedValue: Value) { | |
self.currentValue = wrappedValue | |
} | |
var wrappedValue: Value { | |
get { | |
return self.currentValue | |
} | |
set { | |
history.append(newValue) | |
currentValue = newValue | |
} | |
var projectedValue: Self { | |
return self | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment