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