Created
November 21, 2019 04:28
-
-
Save artemnovichkov/23efbb571186fc2e5b21debdbd39d8c7 to your computer and use it in GitHub Desktop.
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