Last active
November 4, 2016 16:22
-
-
Save jeksys/d001b2757fd86ddab336e6d20ee229e8 to your computer and use it in GitHub Desktop.
unwrapped optional String
This file contains hidden or 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
private protocol _Optional { | |
func unwrappedString() -> String | |
} | |
extension Optional: _Optional { | |
fileprivate func unwrappedString() -> String { | |
switch self { | |
case .some(let wrapped as _Optional): return wrapped.unwrappedString() | |
case .some(let wrapped): return String(describing: wrapped) | |
case .none: return String(describing: self) | |
} | |
} | |
} | |
postfix operator ~? | |
public postfix func ~? <X> (x: X?) -> String { | |
return x.unwrappedString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment