Swift Property Wrapper for logging
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 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