Menu

Finding Swift code nothing reaches with the compiler's index store
📰

Finding Swift code nothing reaches with the compiler's index store

DEV Community: ios·Darkø Tasevski·about 9 hours ago
#uZV575Gs
#devtoios#devto#dev#if#index
Long article (2275 words) — no AI summary yet.
Reading 0:00
15s threshold

This one is about finding dead code in a Swift app, and in particular one kind of dead code that the usual tools can't see at all, a TCA (The Composable Architecture) action that has a reducer arm handling it but that nothing in the app ever sends. I ran into it on a personal iOS app (SwiftUI, TCA and a Rust core, about 4,700 Swift files once tests are counted), where a fix had been moved into exactly such an arm and so never ran, and I wanted a periodic sweep over the whole program that would report actions like that before anyone builds on them.

Why "no references" isn't enough

The shape of the problem looks like this:

struct Item : Equatable { }

@Reducer struct ItemsFeature { @ObservableState struct State : Equatable { var items : [ Item ] = [ ] }

enum Action { case itemsLoaded ( [ Item ] ) case addItem ( Item ) // nothing sends this }

var body : some ReducerOf < Self > { Reduce { state , action in switch action { case let . itemsLoaded ( items ) : state . items = items return . none case let .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.