Created
August 2, 2020 23:28
-
-
Save richimf/08793bb0d89cf30a1e6a9d7a8ed83aaf to your computer and use it in GitHub Desktop.
Property Wrapper
This file contains hidden or 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 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