Skip to content

Instantly share code, notes, and snippets.

@richimf
Created August 2, 2020 23:28
Show Gist options
  • Save richimf/08793bb0d89cf30a1e6a9d7a8ed83aaf to your computer and use it in GitHub Desktop.
Save richimf/08793bb0d89cf30a1e6a9d7a8ed83aaf to your computer and use it in GitHub Desktop.
Property Wrapper
@propertyWrapper struct WhiteSpacesTrimmed {
var projectedValue: String
var wrappedValue: String {
didSet {
self.projectedValue = wrappedValue
wrappedValue = wrappedValue.trimmingCharacters(in: .whitespaces)
}
}
init(wrappedValue:String) {
self.projectedValue = wrappedValue
self.wrappedValue = wrappedValue.trimmingCharacters(in: .whitespaces)
}
}
class TestClass5 {
@WhiteSpacesTrimmed var test = " test"
}
print("projected Values")
var testClass5 = TestClass5()
print(testClass5.test) //"test"
print(testClass5.$test) //" test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment