Stop Xcode from constantly rebuilding your project because of @IBDesignable

If you use Interface Builder along with @IBDesignable attribute you may have noticed that Xcode sometimes builds your project even though you didn’t trigger a build. This is because it needs to compile views marked with @IBDesignable to be able to render them in Interface Builder. What's problematic is that these builds seem to occur a bit too often.

After closer inspection, I managed to notice what happens without having to disassemble Xcode. Xcode can be in two states:

  1. Default state:
    • You can edit all source files and save them, without Xcode triggering builds needed for IB rendering.
  2. Once you open any XIB or storyboard file that references a view marked as @IBDesignable:
    • Saving any source file (not even a view) associated with the same target will now cause an automatic rebuild of the project.
    • What’s more, even after you’ve closed all Interface Builder tabs, the behavior will persist until you reopen the project. I think this is a bug (reported as rdar://35558659).

Thankfully, you can disable these automatic rebuilds by opening any file in Interface Builder, going to Editor menu and unchecking Automatically Refresh Views.

Deselect "Automatically Refresh Views" if Xcode rebuilds your project too often

After this change, you’ll now have to manually trigger an IB-specific build when you want to see the preview of your @IBDesignable views. I recommend setting up a key binding for Refresh All Views option if you use @IBDesignable often.

UPDATE: Tom Brodhurst-Hill mentions on Twitter that some of these issues got fixed/improved in Xcode 9.2 beta 2.