[swift-evolution] [Pitch] Improve String Literals

Ben Rimmington me at benrimmington.com
Tue May 16 14:28:06 CDT 2017


> On 16 May 2017, at 16:36, Gwendal Roué wrote:
> 
>> Le 16 mai 2017 à 16:58, Tony Allevato <tony.allevato at gmail.com> a écrit :
>> 
>> Regarding the C/Objective-C syntax, what would be the advantages over concatenating the strings with `+`?
> 
> The support for ExpressibleByStringLiteral and ExpressibleByStringInterpolation protocols.

Would it be possible to have compile-time concatenation of *all* string literals using the `+` operator?

	// Written as:
	@available(*, unavailable, message: "Long strings can be bro" +
	                                    "ken into two or more pieces.")
	// Compiled as:
	@available(*, unavailable, message: "Long strings can be broken into two or more pieces.")

This could also be used with types such as StaticString, which don't have their own `+` operator.

	// Written as:
	let s: StaticString = "Long strings can be bro" +
	                      "ken into two or more pieces."
	// Compiled as:
	let s: StaticString = "Long strings can be broken into two or more pieces."

-- Ben



More information about the swift-evolution mailing list