函數
debug
debugPrint(_:separator:terminator:to:)
將最適合調試的給定項目的文本表示寫入給定輸出流。
聲明
func debugPrint<Target>(
_ items: Any...,
separator: String = " ",
terminator: String = "\n",
to output: inout Target
) where Target : TextOutputStream
參數
items
零個或多個要打印的項目。
separator
在每個項目之間打印的字符串。默認值為單個空格 (
" "
)。terminator
打印完所有項目後要打印的字符串。默認為換行符 (
"\n"
)。output
用於接收每個項目的文本表示的輸出流。
詳述
您可以將零個或多個項目傳遞給debugPrint(_:separator:terminator:to:)
函數。每個項目的文本表示與調用 String(reflecting: item)
獲得的相同。以下示例將整數的封閉範圍打印到字符串:
var range = "My range: "
debugPrint(1...5, to: &range)
// range == "My range: ClosedRange(1...5)\n"
要打印由空格以外的其他內容分隔的項目,請將字符串作為 separator
傳遞。
var separated = ""
debugPrint(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"
默認情況下,每次調用 debugPrint(_:separator:terminator:to:)
的輸出都包含一個換行符。要打印沒有尾隨換行符的項目,請將空字符串作為 terminator
傳遞。
var numbers = ""
for n in 1...5 {
debugPrint(n, terminator: "", to: &numbers)
}
// numbers == "12345"
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相關用法
- Swift debugPrint(_:separator:terminator:)用法及代碼示例
- Swift KeyValuePairs flatMap(_:)用法及代碼示例
- Swift String.UTF8View first用法及代碼示例
- Swift Result.Publisher zip(_:_:_:)用法及代碼示例
- Swift Optional.Publisher reduce(_:_:)用法及代碼示例
- Swift Int8 ~(_:)用法及代碼示例
- Swift SetAlgebra isStrictSubset(of:)用法及代碼示例
- Swift UInt +(_:)用法及代碼示例
- Swift Array enumerated()用法及代碼示例
- Swift FlattenSequence prefix(_:)用法及代碼示例
- Swift Slice endIndex用法及代碼示例
- Swift LazySequence split(maxSplits:omittingEmptySubsequences:whereSeparator:)用法及代碼示例
- Swift MutableCollection partition(by:)用法及代碼示例
- Swift ReversedCollection min(by:)用法及代碼示例
- Swift RandomNumberGenerator用法及代碼示例
- Swift Dictionary.Keys shuffled()用法及代碼示例
- Swift AnySequence elementsEqual(_:)用法及代碼示例
- Swift UInt &<<(_:_:)用法及代碼示例
- Swift Optional.Publisher tryDrop(while:)用法及代碼示例
- Swift DefaultIndices endIndex用法及代碼示例
- Swift Substring.UnicodeScalarView insert(contentsOf:at:)用法及代碼示例
- Swift LazyFilterSequence dropFirst(_:)用法及代碼示例
- Swift LazySequence suffix(from:)用法及代碼示例
- Swift ArraySlice starts(with:)用法及代碼示例
- Swift Int16.Words max()用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 debugPrint(_:separator:terminator:to:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。