Created
March 28, 2017 15:13
-
-
Save humblehacker/23d323e30f580925d54a34900622f926 to your computer and use it in GitHub Desktop.
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
// Based on https://github.com/T-Pham/NoOptionalInterpolation | |
import Foundation | |
public | |
protocol Unwrappable | |
{ | |
func unwrap() -> Any? | |
} | |
extension Optional: Unwrappable | |
{ | |
public | |
func unwrap() -> Any? | |
{ | |
switch self | |
{ | |
case nil: | |
return nil | |
case let unwrappable as Unwrappable: | |
return unwrappable.unwrap() | |
case let any: | |
return any | |
} | |
} | |
} | |
public | |
extension String | |
{ | |
public | |
init<T:Unwrappable>(stringInterpolationSegment expr: T) | |
{ | |
guard let unwrapped = expr.unwrap() else { self.init("nil")!; return } | |
self.init(reflecting: unwrapped) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment