BLACK FRIDAY: Save 50% on all my Swift books and bundles! >>

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      

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.