Skip to content

Instantly share code, notes, and snippets.

@artemnovichkov
Created November 21, 2019 04:28
Embed
What would you like to do?
Swift Property Wrapper for logging
@propertyWrapper
struct Logging<T> {
var value: T
init(wrappedValue value: T) {
self.value = value
}
var wrappedValue: T {
get {
value
}
set {
self.value = newValue
print(newValue)
}
}
}
//Example
struct Human {
@Logging var age = 26
}
var human = Human()
human.age += 1 // logs "27"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment