Printing messages in the same line in Swift

Swift code to print the messages in same line. When you use the print function it will add a new line at the end, so the next message will be printed on the next line. This code will show you how you can print messages in the same line.

Source code :

print("Hello this is Swift 2.0 !")

print("Swift is ", terminator : "")
print("Awesome !")

Output :

Hello this is Swift 2.0 !
Swift is Awesome !

Notes :

Inorder to print messages in the same line. We have to specify the terminator parameter in the print function. It can be done in this syntax terminator:"character".

In the first print function we haven't specified the terminator, so the new line escape sequence \n will be appened to the end.

In the second print function we have specified the terminator which makes the Awesome ! message in the next print function to get printed on the same line.

Output :


Comments :