In swift we can use both
NSLog() functions to print something on Xcode console.
But there are lot of differences in
NSLog() functions, such as:
NSLog() will print timestamp along with the string we passed to it, but
print() will not print timestamp.
let array = [1, 2, 3, 4, 5] print(array) NSLog(array.description)
[1, 2, 3, 4, 5]
2017-05-31 13:14:38.582 ProjetName[2286:7473287] [1, 2, 3, 4, 5]
It'll also print ProjectName along with timestamp.
2 Only String:
NSLog() only takes String as an input, but
print() can print any type of input passed to it.
let array = [1, 2, 3, 4, 5] print(array) //prints [1, 2, 3, 4, 5] NSLog(array) //error: Cannot convert value of type [Int] to expected argument type 'String'
NSLog() function is very slow compare to
NSLog() handles simultaneous usage from multi-threading environment and prints output without overlapping it. But
print() will not handle such cases and jumbles while prating output.
5 Device Console:
NSLog() outputs on device console also, we can see this output by connecting our device to Xcode.
print() will not print output to device's console.