實例方法
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 Result.Publisher prefix(_:)用法及代碼示例
- Swift Result.Publisher prefix(while:)用法及代碼示例
- Swift Result.Publisher prepend(_:)用法及代碼示例
- Swift Result.Publisher zip(_:_:_:)用法及代碼示例
- Swift Result.Publisher tryLast(where:)用法及代碼示例
- Swift Result.Publisher sink(receiveCompletion:receiveValue:)用法及代碼示例
- Swift Result.Publisher merge(with:_:_:)用法及代碼示例
- Swift Result.Publisher tryCompactMap(_:)用法及代碼示例
- Swift Result.Publisher sink(receiveValue:)用法及代碼示例
- Swift Result.Publisher eraseToAnyPublisher()用法及代碼示例
- Swift Result.Publisher setFailureType(to:)用法及代碼示例
- Swift Result.Publisher first(where:)用法及代碼示例
- Swift Result.Publisher output(at:)用法及代碼示例
- Swift Result.Publisher tryCatch(_:)用法及代碼示例
- Swift Result.Publisher dropFirst(_:)用法及代碼示例
- Swift Result.Publisher merge(with:_:_:_:_:_:_:)用法及代碼示例
- Swift Result.Publisher flatMap(maxPublishers:_:)用法及代碼示例
- Swift Result.Publisher map(_:_:_:)用法及代碼示例
- Swift Result.Publisher catch(_:)用法及代碼示例
- Swift Result.Publisher drop(while:)用法及代碼示例
- Swift Result.Publisher timeout(_:scheduler:options:customError:)用法及代碼示例
- Swift Result.Publisher merge(with:_:)用法及代碼示例
- Swift Result.Publisher map(_:)用法及代碼示例
- Swift Result.Publisher append(_:)用法及代碼示例
- Swift Result.Publisher breakpointOnError()用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Result.Publisher print(_:to:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。