Thursday, July 14, 2022 [Tweets] [Favorites]

Inject: Hot Reloading in Swift

Krzysztof Zabłocki (tweet):

If you only used Apple platforms, you can be surprised to learn how many platforms have embraced hot-reloading decades ago. Whether you write Node or any other JS framework, there is a setup for you to use hot-reloading. Go also offers hot-reloading (This blog leverages that feature).

[…]

Eight years have passed since Swift Playgrounds are still here, and they got better, but are they reliable? […] In my experience: not really.

[…]

Similar story [with SwiftUI Previews], it’s great when it works, but it works unreliably in bigger projects and tends to break more times than they work.

[…]

I recognized that Playgrounds approach might have been too heavy-handed, so today, I’m open-sourcing. A very focused micro-library called Inject that, when paired with InjectionForXcode, will make your Apple development much more efficient and enjoyable!

[…]

Hosts leverage auto-closure, so each time you inject code, we create a new instance of your type with the same arguments as initially, allowing you to iterate on any code, memory layout, and everything else. The only thing that you can’t change is your initializer API.

See also: his previous project Traits.

Previously:

2 Comments

Very nice tool and I respect people who share such usefuls to the community.

However it stops working quite easily and once it stopped there's no go back except rebuilding a project. There's limits what it can do.

If you already have SwiftUI Previews working, I don't recommend it.

> Similar story [with SwiftUI Previews], it’s great when it works, but it works unreliably in bigger projects and tends to break more times than they work.

Even with small projects, it breaks so easily. I don't understand how the person putting that Resume button in there didn't think "hmm, maybe we should simply make this thing auto-resume?"

"Show me a preview of the UI I'm building but also, if I ever have a typo in there for a split second, just stop refreshing the preview and keep showing a state from minutes ago" doesn't strike me as a very useful default behavior.

(I know Xcode 14 significantly changes SwiftUI Previews, so maybe this has been resolved. I'm still on 13.)

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment