Home > Blockchain >  Any way to wrap a long string in Xcode to new line?
Any way to wrap a long string in Xcode to new line?

Time:01-06

I have word-wrapping disabled in Xcode and I try to limit every line to 120 characters. But what can I do when I have a really long string that breaks this limit? I can't find a clean way to wrap it to a new line in Xcode without creating multiple strings.

CodePudding user response:

Since you are using the Swift tag, I'll assume you're programming in swift.

Swift supports multiline strings like this:

var about: String = """
My name is Adam.
I am a software developer.
"""

This will include a newline character at the end of each line. To remove the newline character add a \ to the end of the line.

Example:

var about: String = """
My name is Adam. \
I am a software developer. \
"""

Swift Reference for Multiline Strings

  •  Tags:  
  • Related