[swift-evolution] Thoughts on replacing \() with $() or some other symbol
david at alkaline-solutions.com
Wed Jun 22 12:28:29 CDT 2016
> On Jun 22, 2016, at 4:19 AM, Haravikk via swift-evolution <swift-evolution at swift.org> wrote:
> The following two lines are equivalent:
> return "Value of foo is \(foo), have a nice day!"
> return "Value of foo is " + foo + "have a nice day!" // Assuming foo is a String already
> So in a way you can think of \() as being a means of escaping from the string entirely. I find this more logical than the idea which other languages encourage which is that the variable is somehow embedded inside the string, which is why I actually really like having escape do this in Swift.
The two have equivalent output (excluding the omission of “, “ which I assume was a typo), but go through different code paths. I believe the interpolation has more opportunities for memory optimization.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution