Home iOS & Swift Books RxSwift: Reactive Programming with Swift

Debugging with RxTimelane Written by Marin Todorov

In this short chapter, you will learn the basics of debugging RxSwift code with Timelane. Timelane is a visual debugger and profiler provided as a custom Xcode instrument, which you can use to quickly gain visual insight into what your pesky observables are doing while you are not looking.

Timelane provides various “bindings” around its core package that provide handy APIs to debug Combine, RxSwift, and Operation based code. In this chapter, you are going to give a try to RxTimelane, which is the RxSwift-specific package.

Installing the Timelane Instrument

Before getting started, you’ll need to install Timelane, which you can get from https://github.com/icanzilb/Timelane.

Once installed in your Applications folder, open Timelane and install the Timelane Instrument by clicking on the package icon:

This will spawn a standard Instruments installation dialog; click “Install”:

This will install the Timelane Instrument alongside your standard instruments like Zombies, Time Profiler, Core Animation, etc:

Using the RxTimelane library

The second step you need to take before getting started with debugging is to include the RxTimelane package in your project.

pod 'RxTimelane', '1.0.9'
Installing RxTimelane (1.0.9)
Installing TimelaneCore (1.0.10)

The lane(…) operator

Open the starter project for this chapter. In MainViewController.swift add a new import at the top of the file:

import RxTimelane
  .throttle(.milliseconds(500), scheduler: MainScheduler.instance)

.lane("Photos", transformValue: { "\($0.count) photos" })

Tracking multiple subscriptions

Try logging more subscriptions to Timelane. You can use lane as much as you like. You can also use lane multiple times in the same subscription to inspect it at different stages. Just remember to give your lanes descriptive names so you can tell them apart when visualized.

let newPhotos = photosViewController.selectedPhotos
let newPhotos = photosViewController.selectedPhotos
  .lane("New Photos")

Inspecting values over time

To wrap up this very quick introduction to Timelane, see how you can inspect in a little more detail the values emitted by one of your observables.

import RxTimelane
let authorized = PHPhotoLibrary.authorized
  .lane("Photo Library Auth")

Where to go from here?

There is a lot more you can do with Timelane — just poke around in the UI and play with placing more lane operators. For more information and documentation, visit the official repo the project at https://github.com/icanzilb/Timelane.

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.

Have feedback to share about the online reading experience? If you have feedback about the UI, UX, highlighting, or other features of our online readers, you can send them to the design team with the form below:

© 2021 Razeware LLC

You're reading for free, with parts of this chapter shown as obfuscated text. Unlock this book, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.

Unlock Now

To highlight or take notes, you’ll need to own this book in a subscription or purchased by itself.