aneuryzm aneuryzm - 19 days ago 5
Swift Question

Differences when using print func in Swift and print command in console

I printed the same string from code and in console, and it seems that the

\n
newline character is escaped differently.


  1. Using print function in Swift code:

    print(myString)



output:


"my String

and one more line"



  1. Using print in console (or
    po
    same thing)

    print myString



output:


"my String\nand one more line"


How can I get the same multiline string by using print in console?

Answer Source

The "problem" is merely that lldb is not Swift. So neither po nor print mean what you think they mean. Try this instead:

(lldb) po print("hey\nho")

Basically po is the same as expr; we are saying, "evaluate the following as a Swift expression." So we get Swift's native printing behavior.