Created
June 13, 2017 20:55
-
-
Save xxtesaxx/ecfc0c11a4f6c4164279617f681a0303 to your computer and use it in GitHub Desktop.
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
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