이니셜라이저는 세 개의 인자를 받는다.
이벤트에 대하여 로그 메세지를 출력한다.
다음의 이벤트를 전달받으면 로그 메세지를 출력한다.
매 오퍼레이터 실행 후 Publisher의 상태를 확인하는 등 디버깅 과정에서 유용하게 사용할 수 있다.
// Publishers.Print Publisher
Publishers
.Print(upstream: Just(Void()), prefix: "")
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Print Error")
case .finished:
print("Combine Print Finish")
}
}, receiveValue: {
print("Combine Print")
})
.store(in: &cancellables)
// print Operator
Just(Void())
.print()
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Print Error")
case .finished:
print("Combine Print Finish")
}
}, receiveValue: {
print("Combine Print")
})
.store(in: &cancellables)
// receive subscription: (Just)
// request unlimited
// receive value: (())
// Combine Print
// receive finished
// Combine Print Finish
Observable.just(Void())
.debug()
.subscribe(onNext: {
print("RxSwift Print")
}, onError: { _ in
print("RxSwift Print Error")
}, onCompleted: {
print("RxSwift Print Finish")
})
.disposed(by: disposeBag)
// 2019-10-29 22:11:20.753: ContentViewModel.swift:57 (rxSwift()) -> subscribed
// 2019-10-29 22:11:20.755: ContentViewModel.swift:57 (rxSwift()) -> Event next(())
// RxSwift Print
// 2019-10-29 22:11:20.755: ContentViewModel.swift:57 (rxSwift()) -> Event completed
// RxSwift Print Finish
// 2019-10-29 22:11:20.755: ContentViewModel.swift:57 (rxSwift()) -> isDisposed
SignalProducer(value: Void())
.logEvents()
.start { event in
switch event {
case .value:
print("ReactiveSwift Print")
case .failed:
print("ReactiveSwift Print Error")
case .completed:
print("ReactiveSwift Print Finish")
default:
break
}
}
// [] starting fileName: /Users/presto/Developer/Xcode/ReactivePractice/ReactivePractice/ContentViewModel.swift, functionName: reactiveSwift(), lineNumber: 71
// [] value fileName: /Users/presto/Developer/Xcode/ReactivePractice/ReactivePractice/ContentViewModel.swift, functionName: reactiveSwift(), lineNumber: 71
// ReactiveSwift Print
// [] completed fileName: /Users/presto/Developer/Xcode/ReactivePractice/ReactivePractice/ContentViewModel.swift, functionName: reactiveSwift(), lineNumber: 71
// [] terminated fileName: /Users/presto/Developer/Xcode/ReactivePractice/ReactivePractice/ContentViewModel.swift, functionName: reactiveSwift(), lineNumber: 71
// ReactiveSwift Print Finish
// [] disposed fileName: /Users/presto/Developer/Xcode/ReactivePractice/ReactivePractice/ContentViewModel.swift, functionName: reactiveSwift(), lineNumber: 71
// [] started fileName: /Users/presto/Developer/Xcode/ReactivePractice/ReactivePractice/ContentViewModel.swift, functionName: reactiveSwift(), lineNumber: 71