### Install downloaded packages via command line Source: https://developer.apple.com/documentation/xcode/downloading-and-installing-additional-xcode-components Set the active Xcode version, perform first-launch setup, and import downloaded platform runtime images. ```bash xcode-select -s /Applications/Xcode-beta.app xcodebuild -runFirstLaunch xcodebuild -importPlatform "~/Downloads/watchOS 9 beta Simulator Runtime.dmg" ``` -------------------------------- ### Documentation Extension Link Example (Framework Module) Source: https://developer.apple.com/documentation/xcode/formatting-your-documentation-content For a documentation extension file, use a symbol link by wrapping the path to the symbol within double backticks (``). This example shows a link starting with a framework module name. ```markdown # ``MyFramework/MyClass`` ``` -------------------------------- ### Install Command Line Tools using xcode-select Source: https://developer.apple.com/documentation/xcode/installing-the-command-line-tools Use this command in Terminal to initiate the download and installation of the Command Line Tools for Xcode. A system dialog will appear to confirm the installation. ```bash % xcode-select --install xcode-select: note: install requested for command line developer tools ``` -------------------------------- ### Example Documentation URL Structure Source: https://developer.apple.com/documentation/xcode/distributing-documentation-to-other-developers This is an example of how a documentation URL might be structured when hosted on a web server, showing paths for reference documentation and tutorials. ```http https://www.example.com/documentation/SlothCreator/SlothGenerator ``` -------------------------------- ### Install Permissions Source: https://developer.apple.com/documentation/xcode/build-settings-reference Permissions used for installed product files. ```APIDOC ## Install Permissions ### Description Permissions used for installed product files. ### Method N/A (Build Setting) ### Endpoint N/A (Build Setting) ### Parameters #### Build Settings - **INSTALL_MODE_FLAG** (string) - Permissions used for installed product files. ### Request Example N/A ### Response N/A ``` -------------------------------- ### Installation Directory Source: https://developer.apple.com/documentation/xcode/build-settings-reference The directory in which to install the build products. This path is prepended by the DSTROOT. ```APIDOC ## Installation Directory ### Description The directory in which to install the build products. This path is prepended by the `DSTROOT`. ### Method N/A (Build Setting) ### Endpoint N/A (Build Setting) ### Parameters #### Build Settings - **INSTALL_PATH** (string) - The directory for installing build products. ### Request Example N/A ### Response N/A ``` -------------------------------- ### Create an Installer package Source: https://developer.apple.com/documentation/xcode/packaging-mac-software-for-distribution Use the productbuild tool to package a single app for distribution. ```shell % productbuild --sign --component /Applications ``` -------------------------------- ### Example: Locate dSYM for a Specific Binary Source: https://developer.apple.com/documentation/xcode/adding-identifiable-symbol-names-to-a-crash-report This example demonstrates using grep to find the binary image entry for 'TouchCanvas' and then using mdfind to search for the corresponding dSYM file based on its build UUID. ```bash % grep --after-context=1000 "Binary Images:" | grep TouchCanvas 0x1022c0000 - 0x1022effff TouchCanvas arm64 <9cc89c5e55163f4ab40c5821e99f05c6> ``` ```bash % mdfind "com_apple_xcode_dsym_uuids == 9CC89C5E-5516-3F4A-B40C-5821E99F05C6" ``` -------------------------------- ### Install Owner Source: https://developer.apple.com/documentation/xcode/build-settings-reference The owner name or uid for installed products. ```APIDOC ## Install Owner ### Description The owner name or `uid` for installed products. ### Method N/A (Build Setting) ### Endpoint N/A (Build Setting) ### Parameters #### Build Settings - **INSTALL_OWNER** (string) - The owner name or `uid` for installed products. ### Request Example N/A ### Response N/A ``` -------------------------------- ### Basic Code Listing Example Source: https://developer.apple.com/documentation/xcode/formatting-your-documentation-content Create a code listing by starting a new paragraph with three backticks (```), followed by the programming language name, then the code, and finally terminating with three backticks. ```markdown ```swift struct Example { func greet() { print("Hello, world!") } } ``` ``` -------------------------------- ### Import Metal Toolchain from file Source: https://developer.apple.com/documentation/xcode/downloading-and-installing-additional-xcode-components Install a previously downloaded Metal Toolchain disk image into Xcode. ```bash xcodebuild -importComponent metalToolchain ~/Downloads/metalToolchain.dmg ``` -------------------------------- ### Install Group Source: https://developer.apple.com/documentation/xcode/build-settings-reference The group name or gid for installed products. ```APIDOC ## Install Group ### Description The group name or `gid` for installed products. ### Method N/A (Build Setting) ### Endpoint N/A (Build Setting) ### Parameters #### Build Settings - **INSTALL_GROUP** (string) - The group name or `gid` for installed products. ### Request Example N/A ### Response N/A ``` -------------------------------- ### Load and Start Daemon Service Source: https://developer.apple.com/documentation/Xcode/signing-a-daemon-with-a-restricted-entitlement Move the configuration file to the LaunchDaemons directory and trigger the service using launchctl. ```shell % sudo cp com.example.apple-samplecode.DaemonInAppsClothing.plist /Library/LaunchDaemons % sudo launchctl load /Library/LaunchDaemons/com.example.apple-samplecode.DaemonInAppsClothing.plist % sudo launchctl start com.example.apple-samplecode.DaemonInAppsClothing ``` -------------------------------- ### Get help for xcodebuild Source: https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle Execute `xcodebuild -help` to view all available command options for `xcodebuild`. ```bash xcodebuild -help ``` -------------------------------- ### App Thinning Size Report Example Source: https://developer.apple.com/documentation/xcode/reducing-your-app-s-size This is an example of the beginning of an app size report generated by Xcode. It shows the compressed and uncompressed sizes for different variants of an app, including 'App + On Demand Resources' and 'App' sizes. ```text App Thinning Size Report for All Variants of ExampleApp Variant: ExampleApp.ipa Supported variant descriptors: [device: iPhone11,4, os-version: 12.0], [device: iPhone9,4, os-version: 12.0], [device: iPhone10,3, os-version: 12.0], [device: iPhone11,6, os-version: 12.0], [device: iPhone10,6, os-version: 12.0], [device: iPhone9,2, os-version: 12.0], [device: iPhone10,5, os-version: 12.0], [device: iPhone11,2, os-version: 12.0], and [device: iPhone10,2, os-version: 12.0] App + On Demand Resources size: 6.7 MB compressed, 18.6 MB uncompressed App size: 6.7 MB compressed, 18.6 MB uncompressed On Demand Resources size: Zero KB compressed, Zero KB uncompressed // Other Variants of Your App. ``` -------------------------------- ### Example: Symbolicate a Specific Address with atos Source: https://developer.apple.com/documentation/xcode/adding-identifiable-symbol-names-to-a-crash-report This example shows how to use the atos command to symbolicate a specific address (0x00000001022df754) for the 'TouchCanvas' binary, given its architecture, dSYM path, and load address. ```bash % atos -arch arm64 -o TouchCanvas.app.dSYM/Contents/Resources/DWARF/TouchCanvas -l 0x1022c0000 0x00000001022df754 ViewController.touchesEstimatedPropertiesUpdated(_:) (in TouchCanvas) + 304 ``` -------------------------------- ### Example Custom URL Formats Source: https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app These examples show the format for custom URLs that can be used to reference specific content within an app, such as an album by name or index. ```text myphotoapp:albumname?name="albumname" myphotoapp:albumname?index=1 ``` -------------------------------- ### Export Metal Toolchain to file Source: https://developer.apple.com/documentation/xcode/downloading-and-installing-additional-xcode-components Download the Metal Toolchain and save it to a specific directory for later installation. ```bash xcodebuild -downloadComponent metalToolchain -exportPath ~/Downloads ``` -------------------------------- ### View libWaffleVarnish directory structure Source: https://developer.apple.com/documentation/xcode/embedding-nonstandard-code-structures-in-a-bundle Example directory layout for a nonstandard code structure. ```text libWaffleVarnish/ bin/ wafflevarnish etc/ wafflevarnish.config lib/ libVarnish.dylib libWaffle.dylib ``` -------------------------------- ### Documentation Extension Link Example (Top-Level Symbol) Source: https://developer.apple.com/documentation/xcode/formatting-your-documentation-content For a documentation extension file, use a symbol link by wrapping the path to the symbol within double backticks (``). This example shows a link starting with a top-level symbol name. ```markdown # ``MyClass`` ``` -------------------------------- ### Example Build Settings Source: https://developer.apple.com/documentation/xcode/adding-a-build-configuration-file-to-your-project Illustrates common build settings that can be defined in an .xcconfig file, such as controlling active architecture, deployment target, and linker flags. ```text ONLY_ACTIVE_ARCH = YES MACOSX_DEPLOYMENT_TARGET = 11.0 OTHER_LDFLAGS = -lncurses ``` -------------------------------- ### LoginHandler Test using XCTestCase Source: https://developer.apple.com/documentation/xcode/updating-your-existing-codebase-to-accommodate-unit-tests An alternative test case for `LoginHandler` using the `XCTestCase` framework. It achieves the same goal as the previous example by injecting a `StubLoginStorage` during the test setup. ```swift struct StubLoginStorage : LoginStorage { let value: String? init(value: String?) { self.value = value } func string(forKey: String) -> String? { value } } class XCLoginHandlerTests : XCTestCase { var handler: LoginHandler! = nil override func setUp() { handler = LoginHandler(storage: StubLoginStorage(value: "example-username")) } func testHandlerGetsUsernameFromStorage() { XCTAssertEqual(handler.previousUsername, "example-username") } } ``` -------------------------------- ### Post-Clone Script Example Source: https://developer.apple.com/documentation/xcode/writing-custom-build-scripts A post-clone script runs after Xcode Cloud clones your Git repository. Use it to install additional tools or modify property lists. Always include a shebang. ```shell #!/bin/sh # Example: Install a third-party tool echo "Running post-clone script..." # Add commands here to install tools, e.g., using Homebrew # brew install fastlane exit 0 ``` -------------------------------- ### Example documentation URL structure Source: https://developer.apple.com/documentation/Xcode/distributing-documentation-to-other-developers The web app renders documentation using specific URL paths for symbols and tutorials. ```text https://www.example.com/documentation/SlothCreator/SlothGenerator ``` -------------------------------- ### Sign DaemonWithApp Example for Developer ID Distribution Source: https://developer.apple.com/documentation/xcode/creating-distribution-signed-code-for-the-mac This sequence of commands demonstrates signing various components of the DaemonWithApp example for Developer ID distribution, including frameworks, app extensions, the main app, and the daemon executable. It utilizes options for re-signing (-f), timestamping (--timestamp), enabling Hardened Runtime (-o runtime), and specifying entitlements (--entitlements) and bundle identifiers (-i). ```bash % codesign -s "Developer ID Application" -f --timestamp "to-be-signed/ConfigApp.app/Contents/Frameworks/Core.framework" to-be-signed/ConfigApp.app/Contents/Frameworks/Core.framework: replacing existing signature % codesign -s "Developer ID Application" -f --timestamp -o runtime --entitlements "Share.entitlements" "to-be-signed/ConfigApp.app/Contents/PlugIns/Share.appex" to-be-signed/ConfigApp.app/Contents/PlugIns/Share.appex: replacing existing signature % codesign -s "Developer ID Application" -f --timestamp -o runtime --entitlements "ConfigApp.entitlements" "to-be-signed/ConfigApp.app" to-be-signed/ConfigApp.app: replacing existing signature % codesign -s "Developer ID Application" -f --timestamp -o runtime -i "com.example.apple-samplecode.DaemonWithApp.Daemon" "to-be-signed/Daemon" to-be-signed/Daemon: replacing existing signature ``` -------------------------------- ### Deploy Daemon to System Directory Source: https://developer.apple.com/documentation/Xcode/signing-a-daemon-with-a-restricted-entitlement Create the target directory and copy the built application bundle to the system library location. ```shell % sudo mkdir "/Library/Application Support/DaemonInAppsClothing" % sudo cp -R "DaemonInAppsClothing.app" "/Library/Application Support/DaemonInAppsClothing/" ``` -------------------------------- ### Check Installed Command Line Tools Version Source: https://developer.apple.com/documentation/xcode/installing-the-command-line-tools After installation, use this command with `pkgutil` to verify the version of the installed Command Line Tools package. This is useful to ensure you have the correct version for your development needs. ```bash % pkgutil --pkg-info=com.apple.pkg.CLTools_Executables ``` -------------------------------- ### Dynamic Library Install Name Source: https://developer.apple.com/documentation/xcode/build-settings-reference Sets the internal `install path` (`LC_ID_DYLIB`) in a dynamic library, affecting how `dyld` locates it. ```APIDOC ## Dynamic Library Install Name ### Description Sets an internal `install path` (`LC_ID_DYLIB`) in a dynamic library. Any clients linked against the library will record that path as the way `dyld` should locate this library. If this option is not specified, then the `-o` path will be used. This setting is ignored when building any product other than a dynamic library. See Dynamic Library Programming Topics. ### Setting Name `LD_DYLIB_INSTALL_NAME` ``` -------------------------------- ### Create an XCFramework bundle from static libraries Source: https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle This command creates an XCFramework bundle from static library files (`.a`) and their corresponding header files. Replace `-framework` with `-library` and use the `-headers` flag to specify the path to the header files. ```bash xcodebuild -create-xcframework -library products/iOS/usr/local/lib/libMyLibrary.a -headers products/iOS/usr/local/include -library products/iOS_Simulator/usr/local/lib/libMyLibrary.a -headers products/iOS/usr/local/include -library products/macOS/usr/local/lib/libMyLibrary.a -headers products/macOS/usr/local/include -library products/Mac\ Catalyst/usr/local/lib/libMyLibrary.a -headers products/Mac\ Catalyst/usr/local/include -output xcframeworks/MyLibrary.xcframework ``` -------------------------------- ### Environment Variables for Specific Start Conditions Source: https://developer.apple.com/documentation/xcode/environment-variable-reference These environment variables are only available depending on the specific start condition that triggered the build. ```APIDOC ## Variables for specific start conditions The availability of the following environment variables depends on the workflow’s start condition you configure. For example, the `CI_PULL_REQUEST_NUMBER` variable is only available if the Pull Request Change start condition started the build. ``` -------------------------------- ### Monitor and launch an extension Source: https://developer.apple.com/documentation/xcode/creating-enhanced-security-helper-extensions Discover available extensions using a monitor and launch them using an AppExtensionProcess configuration. ```swift let monitor = try await AppExtensionPoint.Monitor(appExtensionPoint: AppExtensionPoint.exampleExtension) guard let identity = monitor.identities.first else { fatalError("Extension not found") } ``` ```swift do { self.process = try await AppExtensionProcess(configuration: .init(appExtensionIdentity: identity, onInterruption: { // The system calls this closure when the extension exits. })) // Communicate with the extension. } catch let error { // The system can't launch the extension. } ``` -------------------------------- ### Example Exception Type in Crash Report Source: https://developer.apple.com/documentation/xcode/understanding-the-exception-types-in-a-crash-report This is an example of how an exception type is recorded in a crash report. It indicates a memory access error. ```text Exception Type: EXC_BAD_ACCESS (SIGSEGV) ``` -------------------------------- ### Italic Text Example Source: https://developer.apple.com/documentation/xcode/formatting-your-documentation-content Wrap text in single underscores (_) or single asterisks (*) to apply italic styling. This example italicizes new or alternative terms. ```markdown Use italics for _metabolism_ and _habitat_. ``` -------------------------------- ### Bold Text Example Source: https://developer.apple.com/documentation/xcode/formatting-your-documentation-content Wrap text in double asterisks (**) or double underscores (__) to apply bold styling. This example bolds sloth names. ```markdown The sloths are **Brad** and **Chad**. ``` -------------------------------- ### Create and navigate to a new directory Source: https://developer.apple.com/documentation/xcode/embedding-a-helper-tool-in-a-sandboxed-app Use these commands to create a new directory for your tool and change into it. ```shell % mkdir ToolC % cd ToolC ``` -------------------------------- ### Install CocoaPods dependencies in a custom script Source: https://developer.apple.com/documentation/xcode/making-dependencies-available-to-xcode-cloud Use this script in a ci_post_clone.sh file to install dependencies managed by CocoaPods when the Pods directory is excluded from source control. ```shell #!/bin/sh # Install dependencies you manage with CocoaPods. pod install ``` -------------------------------- ### Determine binary architectures Source: https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle Use the file command to inspect the supported architectures of framework or library binaries. ```shell file /.framework/ ``` ```shell file /libMyLibrary.a ``` -------------------------------- ### UIKit WeatherView Preview Source: https://developer.apple.com/documentation/xcode/previewing-your-apps-interface-in-xcode Shows how to preview a UIKit WeatherView. This example instantiates the view and sets its icon property using a system image. ```swift class WeatherView: UIView { var icon: UIImage? } // A UIKit UIView preview. #Preview { let view = WeatherView() if let image = UIImage(systemName: "sun.max.fill") { view.icon = image } return view } ``` -------------------------------- ### Display Command Line Tools Package Information Source: https://developer.apple.com/documentation/xcode/installing-the-command-line-tools This command provides detailed information about the installed Command Line Tools package, including its ID, version, volume, location, and installation time. ```bash % pkgutil --pkg-info=com.apple.pkg.CLTools_Executables package-id: com.apple.pkg.CLTools_Executables version: 26.1.0.0.1.1760670222 volume: / location: / install-time: 1761350460 ```