Avatar ·

What is the difference between print(), println() and NSLog() in Swift and which one is better to use?

Hello everyone! I recently started learning Swift and noticed that there are three different ways to output information to the console: print(), println() and NSLog(). Previously, I wrote in Python, where everything is simple — one print() and done. But here I got confused. For example, I write simple code: let name = "Alexey" let age = 28 print("Name: \(name), age: \(age)") println("Name: \(name), age: \(age)") NSLog("Name: \(name), age: \(age)") All three lines output something to the console, but the format is different. NSLog adds date, time, process name and some identifier. And println doesn't compile at all in Xcode 15 — it says there is no such function. I read old articles (2014–2016) where it was said that println() was used in Swift 1.x, and then it was removed. But some developers