Created
October 26, 2019 08:56
-
-
Save nsoojin/5b47bebc9751f9a673aaf0b1a9150114 to your computer and use it in GitHub Desktop.
ClampedString Property Wrapper
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 ClampedString { | |
let max: Int | |
var value: String | |
init(wrappedValue: String, max: Int) { | |
value = wrappedValue | |
self.max = max | |
} | |
var wrappedValue: String { | |
get { value } | |
set { value = String(newValue.prefix(max)) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment