Print Items with Specific Separator
To print items with specific separator, pass the separator value for the separator
optional parameter of print()
function.
The syntax to specify a separator for printing items is
print(items, separator: mySeparator)
The default value of separator is " "
, a single space.
Swift Example
In this example, we will print items to output with hyphen "-"
as separator.
main.swift
import Foundation
print("abc", "mno", "xyz", separator: "-")
Program Output
abc-mno-xyz
Now, let us try with newline as separator.
main.swift
import Foundation
print("abc", "mno", "xyz", separator: "\n")
Program Output
abc
mno
xyz
Summary
We have learnt how to print items with a specific separator in print() function call, in Swift.