r/iOSProgramming • • 16m ago

Article Open-sourced Snagless: SwiftUI @Environment crashes caught at build time, using SwiftSyntax

Our codebase has hundreds of `@Environment` call sites. Any one of them can crash in production with "No Observable object of type X found" if a view gets shown without the value injected somewhere above it, and the compiler can't see it. Every fix I found started with "first, change all your call sites."

So I built Snagless, a SwiftPM/Xcode build plugin. It reads your SwiftUI source with SwiftSyntax, works out which view shows which across modules, and fails the build when a view can appear without a value it needs. Zero code changes, about 90 ms on a 431-file app.

Built with Claude Code, and the write-up is upfront about every time the AI was wrong and what caught it.

Write-up: https://tarek-builds.dev/p/swiftui-environment-crashes-compile-just-fine-so-i-made-them-fail-the-build/
Repo: https://github.com/tareksabry1337/snagless

Happy to answer questions.

1 Upvotes

0 comments sorted by