實例方法
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:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。