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