Skip to content

Instantly share code, notes, and snippets.

@xxtesaxx
Created June 13, 2017 20:55
Show Gist options
  • Save xxtesaxx/ecfc0c11a4f6c4164279617f681a0303 to your computer and use it in GitHub Desktop.
Save xxtesaxx/ecfc0c11a4f6c4164279617f681a0303 to your computer and use it in GitHub Desktop.
extension Optional where Wrapped == String {
func orWhenNilOrEmpty(_ defaultValue: String) -> String {
switch(self) {
case .none:
return defaultValue
case .some(let value) where value.isEmpty:
return defaultValue
case .some(let value):
return value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment