实例方法
breakpoint(receive
breakpoint(receiveSubscription:receiveOutput:receiveCompletion:)
当提供的闭包需要停止调试器中的进程时,引发调试器信号。
声明
func breakpoint(
receiveSubscription: ((Subscription) -> Bool)? = nil,
receiveOutput: ((Self.Output) -> Bool)? = nil,
receiveCompletion: ((Subscribers.Completion<Self.Failure>) -> Bool)? = nil
) -> Publishers.Breakpoint<Self>
返回值
当提供的闭包之一返回 true
时引发调试器信号的发布者。
参数
receiveSubscription
当发布者收到订阅时执行的闭包。从此闭包中返回
true
以引发SIGTRAP
,或返回 false 以继续。receiveOutput
当发布者收到一个值时执行的闭包。从此闭包中返回
true
以引发SIGTRAP
,或返回 false 以继续。receiveCompletion
当发布者收到完成时执行的闭包。从此闭包中返回
true
以引发SIGTRAP
,或返回 false 以继续。
详述
使用Publisher/breakpoint(receiveSubscription:receiveOutput:receiveCompletion:)
检查订阅/发布/完成过程的一个或多个阶段,并根据您指定的条件在调试器中停止。当任何提供的闭包返回 true
时,此运算符会引发 SIGTRAP
信号以停止调试器中的进程。否则,此发布者按原样传递值和完成。
在下面的示例中,PassthroughSubject
将字符串发布到断点重新发布器。当断点接收到字符串“DEBUGGER
”时,它返回true
,这会在调试器中停止应用程序。
let publisher = PassthroughSubject<String?, Never>()
cancellable = publisher
.breakpoint(
receiveOutput: { value in return value == "DEBUGGER" }
)
.sink { print("\(String(describing: $0))" , terminator: " ") }
publisher.send("DEBUGGER")
// Prints: "error: Execution was interrupted, reason: signal SIGTRAP."
// Depending on your specific environment, the console messages may
// also include stack trace information, which is not shown here.
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相关用法
- Swift Result.Publisher breakpointOnError()用法及代码示例
- 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 print(_:to:)用法及代码示例
- 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 prefix(_:)用法及代码示例
- Swift Result.Publisher timeout(_:scheduler:options:customError:)用法及代码示例
- Swift Result.Publisher merge(with:_:)用法及代码示例
- Swift Result.Publisher map(_:)用法及代码示例
- Swift Result.Publisher append(_:)用法及代码示例
- Swift Result.Publisher handleEvents(receiveSubscription:receiveOutput:receiveCompletion:receiveCancel:receiveRequest:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 Result.Publisher breakpoint(receiveSubscription:receiveOutput:receiveCompletion:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。