BS
BleepingSwift
Published on

> Fixing Xcode Indexing That's Stuck or Slow

Authors
  • avatar
    Name
    Mick MacCallum
    Twitter
    @0x7fs

Few things are more frustrating than watching Xcode's "Indexing" status spin for hours while your autocomplete returns nothing useful. The index is what powers code completion, jump-to-definition, and find-in-project, so when it breaks, your entire development experience suffers. Here's how to diagnose what's wrong and fix it.

How to Tell If Indexing Is the Problem

Look at the status bar at the top of the Xcode window. If it says "Indexing" for more than a few minutes on a moderately-sized project, something's wrong. On a typical project, indexing should complete within a minute or two after opening.

Symptoms of indexing issues include autocomplete showing "No Completions" or only basic suggestions, Command-clicking symbols doing nothing instead of jumping to definitions, and the Find Navigator returning incomplete results.

Open Activity Monitor and look for a process called com.apple.dt.SKAgent. If it's consuming high CPU constantly, the indexer is working but struggling with something.

Quick Fixes

Start with the basics before diving deeper.

Build your project. Indexing depends on build products. If your project hasn't been built recently, building it (⌘B) often kicks indexing into gear.

Close and reopen the project. Sometimes Xcode's indexer gets into a bad state. Closing the workspace window and reopening it forces a fresh indexing pass.

Restart Xcode. If closing the project doesn't help, quit Xcode entirely. When you relaunch, indexing starts fresh.

Delete the Index

If the quick fixes don't help, the index itself may be corrupted. Deleting it forces Xcode to rebuild from scratch.

Close your project in Xcode first. Then delete the index data. The index is stored in your DerivedData folder:

rm -rf ~/Library/Developer/Xcode/DerivedData/YourProjectName-*/Index

If you're not sure which folder is your project's, you can delete all DerivedData (this clears build products too, so you'll need to rebuild):

rm -rf ~/Library/Developer/Xcode/DerivedData/*

Reopen your project and let indexing complete. It will take longer than usual since it's starting from nothing, but it should finish.

Check for Problematic Code

Certain code patterns cause the indexer to slow down dramatically or hang. The Swift type checker and indexer share some infrastructure, so code that's slow to type-check is also slow to index.

Complex type inference. Long chains of closures or heavily nested generic types force the compiler to do expensive type inference. If you have code like this:

let result = array.map { $0.foo }.filter { $0.bar > 0 }.reduce(0) { $0 + $1.baz }

Adding explicit type annotations can help:

let result: Int = array.map { item -> Foo in item.foo }
    .filter { (foo: Foo) -> Bool in foo.bar > 0 }
    .reduce(0) { (sum: Int, foo: Foo) -> Int in sum + foo.baz }

Large array or dictionary literals. Initializing collections with many elements inline causes type-checking slowdowns:

// This can be slow to index
let data = [
    "key1": ["nested": ["deep": value1]],
    "key2": ["nested": ["deep": value2]],
    // ... hundreds more
]

Move large literals to JSON or plist files and load them at runtime instead.

Overly complex expressions. Arithmetic expressions with many terms, especially mixed with optionals, slow down type checking. Break complex expressions into smaller intermediate variables.

Exclude Generated or Vendored Code

If your project includes large amounts of generated code (protocol buffers, GraphQL types, etc.) or vendored dependencies, the indexer spends time on code you don't need to navigate.

You can tell Xcode to skip indexing specific folders by adding them to your project's build settings. In your target's Build Settings, find "Index While Building" and ensure it's appropriate for your needs.

For folders you never need to jump into, consider moving them outside your source tree and adding them as a separate target or package with indexing disabled.

Check Available Disk Space

The index can grow large on big projects, sometimes several gigabytes. If your disk is nearly full, indexing may fail silently or behave unpredictably. Make sure you have at least a few gigabytes free.

The Nuclear Option

When nothing else works, reset Xcode's caches completely:

  1. Quit Xcode
  2. Delete DerivedData:
    rm -rf ~/Library/Developer/Xcode/DerivedData
    
  3. Delete Xcode caches:
    rm -rf ~/Library/Caches/com.apple.dt.Xcode
    
  4. Delete the module cache:
    rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
    
  5. Restart your Mac
  6. Open Xcode and rebuild

This forces everything to regenerate and resolves corruption that survives lesser resets.

Ongoing Maintenance

To keep indexing healthy, build your project regularly. The indexer uses build products, so a fresh build helps it stay current.

Avoid extremely long files. Files with thousands of lines take longer to index. If you have a file that's grown enormous, consider splitting it.

Keep Xcode updated. Apple regularly improves indexer performance, and staying current gives you those benefits.

If indexing remains problematic on a specific project, it may indicate underlying code complexity issues worth addressing—not just for Xcode, but for compile times and maintainability in general.

subscribe.sh

// Stay Updated

Get notified when I publish new tutorials on Swift, SwiftUI, and iOS development. No spam, unsubscribe anytime.

>

By subscribing, you agree to our Privacy Policy.