Connect with us

Code

Inject – Hot Reloading for Swift applications

Hot reloading workflow helper that enables you to save hours of time each week, regardless if you are using UIKitAppKit or SwiftUI.

TLDR: A single line of code change allows you to live code UIKit screen:

 

Read detailed article about this

The heavy lifting is done by the amazing InjectionForXcode. This library is just a thin wrapper to provide the best developer experience possible while requiring minimum effort.

I’ve been using it for years.

What is hot reloading?

Hot reloading is a technique allowing you to get rid of compiling your whole application and avoiding deploy/restart cycles as much as possible, all while allowing you to edit your running application code and see changes reflected as close as possible to real-time.

This makes you significantly more productive by reducing the time you spend waiting for apps to rebuild, restart, re-navigate to the previous location where you were in the app itself, re-produce the data you need.

This can save you literal hours off development time, each day!

Does it add manual overhead to my workflows?

Once you configured your project initially, it’s practically free.

You don’t need to add conditional compilation or remove Inject code from your applications for production, it’s already designed to behave as no-op inlined code that will get stripped by LLVM in non-debug builds.

Which means that you can enable it once per view and keep using it for years to come.

Integration

Initial project setup

To integrate Inject just add it as SPM dependency:

via Xcode

Open your project, click on File → Swift Packages → Add Package Dependency…, enter the repository url (https://github.com/krzysztofzablocki/Inject.git) and add the package product to your app target.

via SPM package.swift

dependencies: [
    .package(
      name: "Inject",
      url: "https://github.com/krzysztofzablocki/Inject.git",
      from: "1.0.5"
    )
]

Individual Developer setup (once per machine)

If anyone in your project wants to use injection, they only need to:

  • You must add “-Xlinker -interposable” (without the double quotes) to the “Other Linker Flags” of all targets in your project for the Debug configuration (qualified by the simulator SDK to avoid complications with bitcode), refer to InjectionForXcode documentation if you run into any issues
  • Download newest version of Xcode Injection from it’s GitHub Page
  • Unpack it and place under /Applications
  • Make sure that the Xcode version you are using to compile our projects is under the default location: /Applications/Xcode.app
  • Run the injection application
  • Select open project / open recent from it’s menu and pick the right workspace file you are using

After choosing the project in Injection app, launch the app

  • If everything is configured correctly you should see similar log in the console:
														
																											
Advertisement

Trending