Skip to content

Instantly share code, notes, and snippets.

@artemnovichkov
Created November 21, 2019 04:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artemnovichkov/23efbb571186fc2e5b21debdbd39d8c7 to your computer and use it in GitHub Desktop.
Save artemnovichkov/23efbb571186fc2e5b21debdbd39d8c7 to your computer and use it in GitHub Desktop.
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