Skip to content

Instantly share code, notes, and snippets.

@serhatsezer
Created December 17, 2015 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serhatsezer/eaffac99779cccec4780 to your computer and use it in GitHub Desktop.
Save serhatsezer/eaffac99779cccec4780 to your computer and use it in GitHub Desktop.
extension by retrofitting gist
let myString: String? = nil
protocol PossiblyEmpty {
var isEmpty: Bool { get }
}
extension String: PossiblyEmpty {}
extension Optional where Wrapped: PossiblyEmpty {
var isEmpty: Bool {
switch self {
case .None: return true
case .Some(let value): return value.isEmpty
}
}
}
myString.isEmpty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment