Xcode build directory is used to save iOS app binary files when you build your Xcode app. Xcode provide you several ways to specify the build output directory location. It can be a unique sub folder or a shared sub folder 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 then Xcode preferences default settings.
1.1 How To Set Xcode Default Build Directory Location.
- Click Xcode —> Preferences… menu item at Xcode top menu bar.
- Then click Locations tab in the popup dialog. In the Derived Data drop down list, you can choose Default, Relative, Custom drop down item. When you select one item, it will display the build output directory absolute path beneath the Derived Data drop down list.
- You can click the Advanced… button to open a Build Location popup dialog to specify the Xcode build directory name and location in detail.
- If you choose 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/…….
- If you choose Shared Folder radio button, you need to input 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 )/Products/Debug-iphonesimulator/……
- If you choose 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.
- If you select Relative to Derived Data, then the build output directory is something like /Users/songzhao/Library/Developer/Xcode/DerivedData/Build/Products/…….
- 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/……, .
- If you select Absolute, then you should specify the build output directory absolute path in related input text box accordingly.
1.2 How To Set Xcode Workspace Build Directory Location.
Besides Xcode default build directory, you can also specify the build directory for each Xcode workspace. Below is the steps.
- Open a workspace in Xcode.
- Click File —> Workspace Settings… menu item at top menu bar.
- It will open the Shared Workspace Settings: popup dialog, you can select different derived data location in the Derived Data drop down list. The value can be Default Location, Workspace-relative Location and Custom Location.
- If you click the Advanced… button, it will popup the workspace Build Location configuration dialog as below. It is similar with the Xcode default build location settings dialog. The only different is that it has a Xcode Default radio button, if you choose this radio button, the Xcode workspace will use Xcode default build location settings.
1.3 How To Set Xcode Project Build Directory.
You can also set Xcode build directory location by each project follow below steps.
- Open a Xcode project.
- Click File —> Project Settings… menu item at top menu bar.
- In the popup Shared Project Settings: dialog, the Derived Data drop down list contains three item, the second item is Project-relative Location. Others are similar with Shared Workspace Settings dialog.
- When you click the Advanced… button, it will popup the project build location dialog, the content of that dialog is similar with workspace build location dialog.
2. How To Get Current Build Output Directory In Xcode.
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 Xcode project navigator pane beneath Products item like below. In this example, the binary file is the red color name .app file under Products item.
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 red color, that means the build is success.
If you want to open above app binary file location folder in mac Finder, just right click the binary file under Products folder, then click Show in Finder menu item in the popup menu list. Then it will open Finder and locate the binary file in the project selected build location directory.