Created
December 4, 2015 10:04
-
-
Save jeremiegirault/a2f41f98f9a41cb88f39 to your computer and use it in GitHub Desktop.
Protocol retrofitting for constrained generic extension in swift
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
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
@jeremiegirault
Swift 3 update:
Change:
.none
.some