Difference between print and println in Swift
print in Swift
In Swift, print() is a function that prints a message to standard output. It takes one or more arguments, which can be any value or expression, and separates them with a space by default. print can’t format anything, it simply takes a string and print it.
Example:
import Foundation print("Welcome to Webeduclick!")
Output:
Welcome to Webeduclick!
println in Swift
The println() function works similarly to print(), but it adds a newline character at the end of the message. This function prints messages in the Xcode console when debugging apps just like the print function.
Example (Swift 1.x):
println("Hello World!")
Output:
Hello World!
Noted: This prints “Hello World!” and moves the cursor to the next line.
Difference between print and println
println | |
---|---|
1. The print function prints messages in the Xcode console when debugging apps. | 1. The println is a variation of this that was removed in Swift 2 and is not used any more. |
2. print didn't add newline characters at the end of the printed string. | 2. println adds newline characters at the end of the printed string. |
3. Print takes one or more arguments, which can be any value or expression, and separates them with a space by default. | 3. Println doesn't take one or more arguments, which can be any value or expression, and separates them with a space by default. |
4. It available after Swift 2.0+ | 4. It available in the Swift 1.0 |