Skip to content

Instantly share code, notes, and snippets.

@luish
Created April 30, 2016 09:45
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 luish/0f5b456323bbdb3366293cf862a3fefb to your computer and use it in GitHub Desktop.
Save luish/0f5b456323bbdb3366293cf862a3fefb to your computer and use it in GitHub Desktop.
protocol StringType {}
extension String: StringType {}
extension Optional where Wrapped: StringType {
var something: Int {
switch self {
case .None: return 10
case .Some(_): return 20
}
}
}
let str: String? = nil
print(str.something) // 10
let str2: String? = "abc"
print(str2.something) // 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment