In this brief tutorial, I’ll introduce you to some useful Xcode command-line tools and present useful use cases where you can leverage their potential.
CI/CD are trendy nowadays, and one of the basic checks that you can set to your repository is to ensure all your targets build. Let’s take a look at some useful commands. But first, open your terminal and run cd path_to_your_project_folder
.
The following command will output a list with all your project settings:
xcodebuild -project MyProject.xcodeproj -showBuildSettings
If you’re looking for one in particular, use grep
to filter. For example, to look up your build directory (BUILD_DIR
):
xcodebuild -project MyProject.xcodeproj -showBuildSettings | grep -m 1 "BUILD_DIR" | grep -oEi "\/.*"
NOTE: You can also use -workspace MyWorkspace.xcworkspace
instead of -project MyProject.xcproject
. This also applies to all the following commands.
To build your scheme, you can run:
xcodebuild clean -scheme MyScheme \
-project MyProject.xcodeproj \
-destination SomeDeviceOrSimulator
If you want a fresh build, add clean
before build
:
xcodebuild clean build -scheme MyScheme \
-project MyProject.xcodeproj \
-destination "platform=macOS"
Here are some destinations you can choose:
"platform=macOS"
"platform=macOS,variant=Mac Catalyst"
"platform=iOS"
"platform=tvOS"
"platform=watchOS"
"platform=iOS Simulator"
You can also choose a specific architecture: "platform=macOS,arch=arm64"
.
#software-development #ios #xcode #ios-app-development #programming