aneuryzm aneuryzm - 3 years ago 269
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

newline character is escaped differently.

  1. Using print function in Swift code:



"my String

and one more line"

  1. Using print in console (or
    same thing)

    print myString


"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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download