函数
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:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。