[swift-evolution] [Draft] Allow multiple conformances to the same protocol

Ben Rimmington me at benrimmington.com
Fri Jun 10 17:29:28 CDT 2016


Brent Royal-Gordon wrote:

> Currently, StringInterpolationConvertible only offers an
> `init<T>(stringInterpolationSegment: T)` initializer.
> That means you absolutely *must* permit any type to be
> interpolated into your type's string literals.

It can be explicitly marked unavailable.

extension LocalizedString : StringInterpolationConvertible {

    @available(*, unavailable)
    public init<T>(stringInterpolationSegment _: T) {
        fatalError()
    }

    public init(stringInterpolationSegment format: String) {
        self.init(format: format, values: [])
    }

    public init(stringInterpolationSegment value: AnyObject) {
        self.init(format: "%@", values: [value])
    }
}

-- Ben




More information about the swift-evolution mailing list