TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Why does Swift need multi-line strings question

Forums > 100 Days of SwiftUI

Tip: Sometimes you will want to have long strings of text in your code without using multiple lines, but this is quite rare. Specifically, this is most commonly important if you plan to share your code with others – if they see an error message in your program they might want to search your code for it, and if you’ve split it across multiple lines their search might fail.

https://www.hackingwithswift.com/quick-start/understanding-swift/why-does-swift-need-multi-line-strings

Hello,

In this page it is described as above. I did not get it. Could you share me a code example where multiple lines can create such an issue?

   

If your code looks like this:

let msg = """
Error: Something has gone wrong with the
quantum defibrillator! Better get it checked
out before proceeding any further.
"""

And the person using your code copies the error message and does a search for it they won't find it because while it's split across multiple lines in the code, when presented to the user it will all be one line. They will have to progressively shorten their search string until they hit upon a substring that will result in a hit.

1      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.