實例方法
print(_:
print(_:to:)
打印所有發布事件的日誌消息。
聲明
func print(
_ prefix: String = "",
to stream: TextOutputStream? = nil
) -> Publishers.Print<Self>
返回值
為所有發布事件打印日誌消息的發布者。
參數
prefix
一個字符串——默認為空——為所有日誌消息添加前綴。
stream
用於接收消息的文本輸出流,默認情況下將輸出定向到控製台。自定義流可用於將消息記錄到其他目的地。
詳述
使用 Publisher/print(_:to:)
在控製台記錄消息。
在下麵的示例中,日誌消息打印在控製台上:
let integers = (1...2)
cancellable = integers.publisher
.print("Logged a message", to: nil)
.sink { _ in }
// Prints:
// Logged a message: receive subscription: (1..<2)
// Logged a message: request unlimited
// Logged a message: receive value: (1)
// Logged a message: receive finished
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相關用法
- Swift Optional.Publisher prepend(_:)用法及代碼示例
- Swift Optional.Publisher reduce(_:_:)用法及代碼示例
- Swift Optional.Publisher tryDrop(while:)用法及代碼示例
- Swift Optional.Publisher debounce(for:scheduler:options:)用法及代碼示例
- Swift Optional.Publisher breakpoint(receiveSubscription:receiveOutput:receiveCompletion:)用法及代碼示例
- Swift Optional.Publisher mapError(_:)用法及代碼示例
- Swift Optional.Publisher catch(_:)用法及代碼示例
- Swift Optional.Publisher tryAllSatisfy(_:)用法及代碼示例
- Swift Optional.Publisher zip(_:_:_:)用法及代碼示例
- Swift Optional.Publisher sink(receiveValue:)用法及代碼示例
- Swift Optional.Publisher scan(_:_:)用法及代碼示例
- Swift Optional.Publisher throttle(for:scheduler:latest:)用法及代碼示例
- Swift Optional.Publisher assertNoFailure(_:file:line:)用法及代碼示例
- Swift Optional.Publisher collect(_:)用法及代碼示例
- Swift Optional.Publisher combineLatest(_:_:_:_:)用法及代碼示例
- Swift Optional.Publisher share()用法及代碼示例
- Swift Optional.Publisher merge(with:_:_:)用法及代碼示例
- Swift Optional.Publisher map(_:_:)用法及代碼示例
- Swift Optional.Publisher assign(to:on:)用法及代碼示例
- Swift Optional.Publisher zip(_:_:_:_:)用法及代碼示例
- Swift Optional.Publisher output(in:)用法及代碼示例
- Swift Optional.Publisher tryReduce(_:_:)用法及代碼示例
- Swift Optional.Publisher map(_:_:_:)用法及代碼示例
- Swift Optional.Publisher removeDuplicates()用法及代碼示例
- Swift Optional.Publisher merge(with:_:_:_:_:_:_:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Optional.Publisher print(_:to:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。