(Resending something that was accidentally off-list.)

> On Nov 1, 2016, at 11:09 PM, Jens Alfke via swift-users 
> <swift-users@swift.org> wrote:
> 
> I don’t think the ExpressibleByStringInterpolation protocol provides enough 
> information to make this work. It hands the implementation a list of values 
> to concatenate, some of which are strings, but as far as I can tell there’s 
> no way to tell which of those strings are the pieces of the string literal 
> and which of them are the results of expressions.

There's actually a simple trick. The even-indexed elements are literal strings; 
the odd-indexed ones are interpolated values. This is true even if you have two 
interpolations adjacent to each other—there will be an empty string between 
them. I've used this for a few different things, including a LocalizableString 
type in Swift 2 and a SQLStatement type in Swift 3.

        https://gist.github.com/brentdax/79fa038c0af0cafb52dd
        
https://github.com/brentdax/swift-sql/blob/master/Sources/SQLStatement.swift

> If I’m wrong about this, show me a workable implementation of it. :)

See above. :^)

> Also, ExpressibleByStringInterpolation is marked as being deprecated and will 
> be “replaced or redesigned in Swift 4.0.” Maybe to solve this limitation?

I believe that making it easier to treat the literal and interpolated segments 
differently is one of the goals.

-- 
Brent Royal-Gordon
Architechies

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to