Generic Function

print(_:separator:terminator:to:)

Writes the textual representations of the given items into the given output stream. 与えられた要素のテキスト表現を与えられた出力ストリームに書き出します。

Declaration 宣言

func print<Target>(_ items: Any..., separator: String = " ", terminator: String = "\n", to output: inout Target) where Target : TextOutputStream

Parameters パラメータ

items

Zero or more items to print. 出力するゼロ個以上の項目

separator

A string to print between each item. The default is a single space (" "). 各項目の間に出力する文字列。初期状態では、単一の空白(" ")です。

terminator

The string to print after all items have been printed. The default is a newline ("\n"). すべての項目が出力された後に出力する文字列。初期状態では改行("\n")です。

output

An output stream to receive the text representation of each item. 各項目のテキスト表現を受け取る出力ストリーム。

Discussion 解説

You can pass zero or more items to the print(_:separator:terminator:to:) function. The textual representation for each item is the same as that obtained by calling String(item). The following example prints a closed range of integers to a string: あなたは、ゼロ個以上の項目をprint(_:separator:terminator:to:)関数に渡すことができます。各項目のテキスト表現は、String(item)を呼び出すことで得られるものと同じです。続く例は、整数の完結範囲をある文字列へ出力します。


var range = "My range: "
print(1...5, to: &range)
// range == "My range: 1...5\n"

To print the items separated by something other than a space, pass a string as separator. 空白以外の何かによって区切られる項目を出力するには、ある文字列をseparatorとして渡してください。


var separated = ""
print(1.0, 2.0, 3.0, 4.0, 5.0, separator: " ... ", to: &separated)
// separated == "1.0 ... 2.0 ... 3.0 ... 4.0 ... 5.0\n"

The output from each call to print(_:separator:terminator:to:) includes a newline by default. To print the items without a trailing newline, pass an empty string as terminator. print(_:separator:terminator:to:)への各呼び出しからの出力は、初期状態では改行を含みます。後に続く改行なしで項目を出力するには、空の文字列をterminatorとして渡してください。


var numbers = ""
for n in 1...5 {
    print(n, terminator: "", to: &numbers)
}
// numbers == "12345"

See Also 参照

Printing and Dumping プリントとダンプ