Chapters

Hide chapters

RxSwift: Reactive Programming with Swift

Fourth Edition · iOS 13 · Swift 5.1 · Xcode 11

22. Debugging with RxTimelane
Written by Marin Todorov

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

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
images
  .lane("Photos")
  .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")
  .share()

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")
  .share()

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.
© 2024 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now