Hot reloading integration with InjectionIll, Inject and Scenarios

November 10, 20224 min read#Swift

The motivation

A common working flow of a iOS developer is:

Writing code -> Compile code -> Start the app on Simulator/Device -> Testing

When the amount of code increases, the time needed to compile code and start the app on smiulators/devices will increase.

Xcode has great support for incremental compilation. But depending on your project structures, a small change in a lower layer can trigger recompilation of the whole app.

Therefore, it’d be great if iOS developers can quickly check a code adjustment for an UI element without recompiling the whole app.

With the introduction of SwiftUI, Xcode has provided live previews capabilities directly in Xcode for this purpose. It works great for simple project, but it normally doesn’t work reliable for real-life projects, and there is no direct support for UIKit-based projects.

This article introduces you to the InjectionIll and Inject tools, and their integrations into Scenarios which enable hot code injection for iOS apps and improve iOS app development workflow.

Hot reloading with InjectionIll, Inject

What is InjectionIll?

Code injection allows you to update the implementation of functions and any method of a class, struct or enum incrementally in the iOS simulator without having to rebuild or restart your application.

InjectionIll provides an infrastructure to inject updated Swift code on-the-fly, while the app is running on Simulators/Devices, without recompiling the whole Xcode project and restart the app.

What is Inject?

Inject is just a thin wrapper of InjectionIll to reduce the effort for integration. With Inject, you can enable Hot Reloading for your UIKit, SwiftUI or AppKit project with some lines of code.

You still need to run the InjectionIll app to make everything working.

Hot reloading Scenarios

Scenarios provides an infrastructure for fast prototyping and feature development for iOS Projects without breaking production apps.

By combining Scenarios + Inject + InjectionIll, developers can accelerate the feature development by spliting a feature into multiple scenarios and using Hot reloading functionality to implement such scenarios even faster.

SwiftUI Demo

This is a demo scenario, implemented in SwiftUI, and can be updated on-the-fly without recompiling.

UIKit Demo

A similar demo for a UIKit Scenario.

Conclusion

For small projects, developers are used to recompile the project for every code change to see their changes on Simulators/Devices.

This process is less productive for large projects where the compilation process might take longer.

Using Scenarios + Inject, developers can accelerate feature development by splitting a feature into smaller tasks and shorten feedback cycle when changing code by seeing their changes immediately without recompiling the whole project.

This improved workflow would save many hours of feature development, and even more when applied in big teams, developing big projects.


Profile picture

Personal blog by An Tran. I'm focusing on creating useful mobile apps.
#Swift #Kotlin #Mobile #MachineLearning #Minimalist


© An Tran - 2022