Skip to content

Instantly share code, notes, and snippets.

@nsoojin
Created October 26, 2019 08:56
Show Gist options
  • Save nsoojin/5b47bebc9751f9a673aaf0b1a9150114 to your computer and use it in GitHub Desktop.
Save nsoojin/5b47bebc9751f9a673aaf0b1a9150114 to your computer and use it in GitHub Desktop.
ClampedString Property Wrapper
@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