How To Configure Xcode Default, Workspace, Project Build Directory Location

Xcode build directory is used to save iOS app binary files when you build your Xcode app. Xcode provides you several ways to specify the build output directory location. It can be a unique subfolder or a shared subfolder in Xcode derived data directory ( in this case all the Xcode projects use one build directory location ), you can also customize the build output folder relative to Xcode derived data directory or relative to your workspace/project or use absolute path. As an iOS developer, it is better for you to know it.

1. How To Configure Xcode Build Directory Location.

You can set Xcode build directory location in Xcode preferences by default or per workspace or per project. Project-level build directory location settings will be used first, then workspace settings will be used,  then Xcode preferences default settings will be used if all the above level settings are not used.

1.1 How To Set Xcode Default Build Directory Location.

  1. Click Xcode —> Preferences… menu item at Xcode top menu bar.
  2. Then click the Locations tab in the popup dialog. In the Derived Data drop-down list, you can choose one of the Default, Relative, Custom drop-down items. When you select one item, it will display the build output directory absolute path beneath the Derived Data drop-down list.
    xcode-preferences-locations
  3. You can click the Advanced… button after the Derived Data directory path to open a Build Location popup dialog to specify the Xcode build directory name and location in detail. There are 4 radio buttons in the Build Location popup dialog, they are Unique, Shared Folder, Custom, Legacy.
  4. If you choose the Unique radio button, then Xcode will add a unique string at the end of the build directory name to make it uniquely. For example /⁨Users/⁨songzhao/⁨Library/⁨Developer⁩/⁨Xcode/⁨DerivedData/⁨SwiftPromptAlertWhenClickButtonExample-aveftcahakzongcarcpgsevmbaur/⁨Build⁩/…….
  5. If you choose the Shared Folder radio button, you need to input the shared folder name in the input text box after it. Then the Xcode build output directory is something like this /Users/songzhao/Library/Developer/Xcode/DerivedData/SharedBuild( this is the shared folder name that you input )/Products/Debug-iphonesimulator/……
  6. If you choose the Custom radio button, then you can select one of the three items from the drop-down list, they are Relative to Derived Data, Relative to Workspace, and Absolute.
  7. If you select Relative to Derived Data, then the build output directory is something like /Users/songzhao/Library/Developer/Xcode/DerivedData/Build/Products/…….
  8. If you select Relative to Workspace, then the Build directory is saved in the current Xcode workspace folder, it is something like /Users/songzhao/Documents/WorkSpace/……/Build/Products/…….
  9. If you select Absolute, then you should specify the build output directory absolute path ( Products, Intermediates, Index Datastore directory path) in the related input text box accordingly.

1.2 How To Set Xcode Workspace Build Directory Location.

Besides the Xcode default build directory, you can also specify the build directory for each Xcode workspace. Below are the steps.

  1. Open a workspace in Xcode.
  2. Click File —> Workspace Settings… menu item at top menu bar.
  3. It will open the Shared Workspace Settings popup dialog, you can select different derived data locations in the Derived Data drop-down list. The value can be Default Location, Workspace-relative Location, and Custom Location.
  4. If you click the Advanced… button, it will popup the workspace Build Location configuration dialog as below. It is similar to the Xcode default build location settings dialog. The only difference is that it has an Xcode Default radio button, if you choose this radio button, the Xcode workspace will use Xcode default build location settings.
    xcode-shared-workspace-location-detail-build-location

1.3 How To Set Xcode Project Build Directory.

You can also set Xcode build directory location for each project follows the below steps.

  1. Open an Xcode project.
  2. Click File —> Project Settings… menu item at top menu bar.
  3. In the popup Shared Project Settings dialog, the Derived Data drop-down list contains three items, the second item is Project-relative Location. Others are similar to the Shared Workspace Settings dialog.
  4. When you click the Advanced… button, it will popup the project build location dialog, the content of that dialog is similar to the workspace build location dialog.

2. How To Get Current Build Output Directory In Xcode.

  1. When you click Product —> Build menu item in Xcode top menu bar to build your project, it will save the target binary file in the build location directory that you selected. And you can see the binary file in the Xcode project navigator pane beneath the Products item. In this example, the binary file is the red color name .app file under Products item.
  2. Please note, if the app binary file name is red color, that means the build is not complete successfully, then you can not open it’s location directory in mac Finder. So you should first make sure the build is complete successfully. When the .app binary file name is not in red color, that means the build is successful.
  3. If you want to open the above app binary file location folder in mac Finder, just right-click the binary file under the Products folder, then click Show in Finder menu item in the popup menu list. Then it will open macOS Finder and locate the binary file in the project selected build location directory.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.