Ever try to type a string containing lots of double quotes, backslashes
or a Regex even?
String literal in any of these cases is an ugly duckling,
filled to the brim with escaped characters, but up until Swift 5
there was no other way, we just had to...
DEAL WITH IT
Here comes Swift Evolution's SE-200
SE-200 proposed a much needed change.
In this proposal "Raw Strings" or
String literals delimited with the pound sign
# at both ends are introduced.
Everything between the starting
# and ending
# is treated as plain text with no special meaning, printed as is.
The string literals that you have been using up to Swift 4.2 are now known as "Conventional" string literals.
And even better yet, lets say that
# is also a character you would like to display unescaped,
in that case just double it:
What about String interpolation?
String interpolation with raw strings is just as simple as with conventional.
In short, in the rare event that you need to display a
in a raw string and need to use multiple
# at the start and end to
escape the string just use the same number of sharps
# after the escaping backslash.
What about Multiline raw Strings?
Yep! Thats a thing too.
Its just as you might have guessed, same rules applied to raw strings
# just now paired with the ruls of multiline strings.
Not too bad
Regular Expressions will surely be easier to write in strings literals
from here on out, as well as double-quote rich strings.
Till next time!