Skip to content

Instantly share code, notes, and snippets.

@DavidBemerguy
Created April 27, 2023 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidBemerguy/5b2b46738ff30c616d78bc97b8b1cacd to your computer and use it in GitHub Desktop.
Save DavidBemerguy/5b2b46738ff30c616d78bc97b8b1cacd to your computer and use it in GitHub Desktop.
Property wrapper that keeps versioning of the property - Very useful for debugging
@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