Tracking down issues – Debugging Rx code
In addition to using traditional debugging techniques, RxSwift
also provides a couple of useful utilities to debug Observable sequences. To demonstrate this, we have created a starter project and initialized a helper class to declare the following two methods, as follows:
publicfunc exampleOf(description: String, actionToPerform: () -> Void) { print(" ===> Example of:", description, "===>") actionToPerform() } publicfunc delayInExecution(_ delayInterval: TimeInterval, actionToPerform: @escaping () -> Void) { DispatchQueue.main.asyncAfter(deadline: .now() + delayInterval) { actionToPerform() } }
The delayInExecution()
wraps a DispatchQueue
to execute an action asynchronously after a delay. As we are working with asynchronous code, we have also imported PlaygroundSupport
and set needsIndefiniteExecution
to true, as follows:
import PlaygroundSupport PlaygroundPage.current.needsIndefiniteExecution = true
We will start by introducing a new type...