Strip Binary Symbols (iOS)

Swift binaries include large amounts of symbols in a segment of the binary used by the dynamic linker. These are generally not needed in production builds. If you build your app with bitcode these symbols will automatically be stripped out. However, Xcode 14 deprecated bitcode by default and Apple will remove the ability to build with bitcode in a future Xcode release. Here's the command to strip symbols for a particular binary:

strip -rSTx AppBinary -o AppBinaryStripped

The T flag tells strip to remove Swift symbols, the other flags remove debugging and local symbols. Symbol stripping can be done automatically by adding a custom "Run Script" build phase at the very end of building, that would look something like:

#!/bin/bash
set -e

# if [ "Release" = "${CONFIGURATION}" ]; then # Only do this for release builds
    
    # Path to the app directory
    APP_DIR_PATH="${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}"
    # Strip main binary
    strip -rSTx "${APP_DIR_PATH}/${EXECUTABLE_NAME}"
    # Path to the Frameworks directory
    APP_FRAMEWORKS_DIR="${APP_DIR_PATH}/Frameworks"
    
    # Strip symbols from frameworks, if Frameworks/ exists at all
    # ... as long as the framework is NOT signed by Apple
    if [ -d "${APP_FRAMEWORKS_DIR}" ]
    then
        find "${APP_FRAMEWORKS_DIR}" -type f -perm +111 -maxdepth 2 -mindepth 2 -exec bash -c 'codesign -v -R="anchor apple" "{}" &> /dev/null || (echo "{}" && strip -rSTx "{}")' \;
    fi
# fi