aotian16 aotian16 - 3 months ago 26
Swift Question

how to use separator param of print in swift2

Sorry for newbee question.

I really do not know how to use separator param in print

var str = "Hello, playground"
var strs = ["abc","def"]

print(str)
print(strs, separator: ",", terminator: "")
print(str, separator: ",", terminator: "\n")

Answer

print accepts its arguments separately, so you can do this:

print("abc", "def", separator: ",")

But you have an array of strings, so you should do this:

print(strs.joinWithSeparator(","))