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 String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.