Skip to content

Instantly share code, notes, and snippets.

@serhatsezer
Created December 17, 2015 21:49
Embed
What would you like to do?
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