The go-to fix for random build issues and bugs in Xcode is to delete the DerivedData directory. The shortcut for that is holding alt/option with the Product menu open: Clean Build Folder, or the keyboard shortcut ⌥⌘⇧K
.
The venerable DerivedData directory is the Xcode equivalent of the build directory from your Makefile days. Except, by default it is not relative to your project source. Instead, it is in a unique (as in UUID) location under ~/Library/Developer/Xcode/
.
I prefer a relative build directory because it’s closer to how you might be building your project from command line or CI scripts. Not having to divine where Xcode is keeping your object files is important for reasoning about how your code is (not) compiling.
And of course, it’s easier to blow it away with a quick rm
!
So let’s change that default and take our build back.
Open up Xcode’s preferences window from the menu-bar, and change to the Locations tab. Change the Derived Data location to Relative as shown:
Under the Advanced settings you can change the Build directory. Be warned, if you change this Xcode will no longer Clean Build Folder for you with the keyboard shortcut ⌥⌘⇧K
.
1- keyboard shortcut ⌥⌘⇧K ( Option Cmd Shift K )
Update
Some great feedback came through from Twitter.
First I want to clarify. The only reason I recommend this configuration is for when problems aren’t being fixed by a Command-Shift-K Clean in Xcode.
Unit Tests not being recognised. Interface Builder Designables not building. Headers not being found.
Usually you can fix it with a clean, building for test, refreshing all views, or restarting Xcode. But sometimes it just won’t give — and I’m not the only one.
Your milage may vary.
Then a tweet happened
I wrote about my old friend, DerivedData. My preferred preferences.
http://t.co/hnSaItNqGl
#iOSDev
— Ashton (@AshtonDev) March 3, 2015
@tonyarnold and @mokagio kicked off a discussion, pulling in @joar_at_work
@tonyarnold Let me preface my other comments with: Everything is a tradeoff… @AshtonDev @mokagio
— Joar Wingfors (@joar_at_work) March 4, 2015
@tonyarnold The default location provides correct behavior with no required user configuration. @AshtonDev @mokagio
— Joar Wingfors (@joar_at_work) March 4, 2015
@tonyarnold The “next to the project” model doesn’t work out of the box when multiple projects contribute to the build. @AshtonDev @mokagio
— Joar Wingfors (@joar_at_work) March 4, 2015
@AshtonDev Yeah, workspace-relative should provide the same benefit. @tonyarnold @mokagio
— Joar Wingfors (@joar_at_work) March 4, 2015
@AshtonDev Don’t let that stand. Please try to analyze how you end up in these situations, and file bug reports! @tonyarnold @mokagio
— Joar Wingfors (@joar_at_work) March 4, 2015