Member-only story
Swift: print() vs println() vs NSLog()
A few differences:
print
vsprintln
:
The print
function prints messages in the Xcode console when debugging apps.
The println
is a variation of this that was removed in Swift 2 and is not used any more. If you see old code that is using println
, you can now safely replace it with print
.
Back in Swift 1.x, print
didn't add newline characters at the end of the printed string, whereas println
did. But nowadays, print
always adds the newline character at the end of the string, and if you don't want it to do that, supply a terminator
parameter of ""
.
2 NSLog
NSLog
is slower;NSLog
adds a timestamp and identifier to the output, whereasprint
will not;NSLog
statements appear in both the device's console and debugger's console whereasprint
only appears in the debugger console.NSLog
usesprintf
-style format strings, e.g.NSLog("%0.4f", CGFloat.pi)
- that will produce:
2017–06–09 11:57:55.642328–0700 MyApp[28937:1751492] 3.1416
For more about iOS development : https://medium.com/@javedmultani16
Some useful codes and libraries: https://github.com/javedmultani16
Know more about me: https://www.linkedin.com/in/javedmultani16/