Cover image for Bringing In The Missing Part: A Code-Generation Tool That Makes Uber's RIBs Usable.

Bringing In The Missing Part: A Code-Generation Tool That Makes Uber's RIBs Usable.

ivanmisuno profile image Ivan Misuno ・2 min read

I've had the privilege of using Uber's RIBs framework and corresponding coding pattern from the very beginning as a member of Uber's engineering team in Amsterdam. There was one thing that made it possible to adopt the protocol-based approach and easily write unit tests in a RIBs-based application: a code-generation tool that picked up protocol definitions from the sources of the program and generated mock classes for the protocols. Uber open-sourced RIBs framework in 2017 but did not include the code-generation tools along with it. I saw huge benefits of adopting RIBs architectural patterns in several projects I was involved in, but without a powerful mocking tool, the adoption would be problematic. In this article, I'm introducing the code-generation template that is powerful enough to cover typical use cases found in a complex application that fully adopts RIBs architecture and provides a few useful shortcuts for RxSwift types.

Introducing swift-sourcery-templates (Beta)

swift-sourcery-templates repository contains two code-generation templates (to be used along with Sourcery engine):

  1. Mocks.swifttemplate — to generate advanced protocol mock classes that can be used as test doubles in place of object dependencies for unit-testing;
  2. TypeErase.swifttemplate — to generate advanced type erasures.

Both templates support protocols with associated types and generic functions (with constraints on generic types),
provide reasonable default values for primitive types, and support advanced types and use cases typically found in projects
that use RxSwift, and, in particular, User's RIBs frameworks.

Sample Project

Along with the templates' documentation, I'm planning on publishing the tutorial article. Meanwhile, I'm developing an accompanying project, please feel free to check it out and give code-generation templates a try.

Would appreciate any feedback!


Posted on by:

ivanmisuno profile

Ivan Misuno


Software Engineer | Ex-Uber | Founder @TheTimeDonors| Leading iOS teams to build applications at scale


markdown guide