Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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