转自 http://stackoverflow.com/questions/25951195/swift-print-vs-println-vs-nslog#
-
println
vsprint
:Prior to Swift 2,
println
would add a newline at the end of the results, whereasprint
would not.Starting in Swift 2,
println
is no longer used. One would generally useprint
(either withoutappendNewline
parameter, or having that parameter set totrue
) to print a line followed with a newline character. You would useprint
withappendNewline
offalse
if you want to print a string without a newline at the end. -
NSLog
vsprint
/println
:-
NSLog
is slower; -
NSLog
adds a timestamp and identifier to the output, whereasprintln
will not; -
NSLog
synchronizes the log statements so that if you're issuing logs from different threads concurrently, they won't overlap with each other;println
can result in jumbled output if performed simultaneously from separate threads without doing some synchronization (e.g. dispatching it to some serial queue, such as the main queue); -
When performed on physical device,
NSLog
statements appear in the device's console whereasprintln
only appears in the debugger console.
-
Generally in Swift, you'd use print
/println
, though you can use NSLog
, when needed (e.g., it's critical that it appears in the console or if you're doing this from multiple threads and you don't want to have to synchronize this yourself). Either of these should be able to display your dictionary without incident.
you can pass in an NSString to println, but not NSLog; you can add args for NSLog, but not println; Swift style string interpolation sometimes crashes for NSLog, but not println.