Skip to content

Instantly share code, notes, and snippets.

@dnpp73
Created February 17, 2021 14:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dnpp73/4f9c12ad96909355a39b99e22e42eb14 to your computer and use it in GitHub Desktop.
Save dnpp73/4f9c12ad96909355a39b99e22e42eb14 to your computer and use it in GitHub Desktop.
#!/bin/bash
# place this shell script to
# ./
# ├── bin/
# │   └── ibdesignable-workaround.sh
# └── YourGreatApp.xcodeproj
set -euo pipefail
if [ "$(uname -m)" != 'arm64' ]; then
echo '[INFO] This workaround script is M1 Mac Only.'
exit
fi
SRCROOT=$(cd "$(dirname "$0")/../" || exit 1; pwd)
echo "SRCROOT: ${SRCROOT}"
cd "${SRCROOT}" || exit 1
# get 'YourGreatApp' string from './YourGreatApp.xcodeproj'
PROJECT_NAME=$(find . -maxdepth 1 -name '*.xcodeproj' | cut -d '/' -f2 | cut -d '.' -f1)
PROJECT="${PROJECT_NAME}"
echo "PROJECT: ${PROJECT}"
echo "PROJECT_NAME: ${PROJECT_NAME}"
# find /${PROJECT_NAME}-[a-z]{28}/ named directory from default DerivedData
cd "${HOME}/Library/Developer/Xcode/DerivedData" || exit 1
BUILD_DIR="$(find . -maxdepth 1 -type d -regextype posix-basic -regex "\./${PROJECT_NAME}-[a-z]\{28\}")"
cd "${BUILD_DIR}/Build/Products" || exit 1
BUILD_DIR=$(pwd)
BUILD_ROOT="${BUILD_DIR}"
echo "BUILD_DIR: ${BUILD_DIR}"
echo "BUILD_ROOT: ${BUILD_ROOT}"
# workaround
find . -maxdepth 1 -name '*-iphonesimulator' -print0 | while read -r -d '' file; do
echo "[info] rm -rf '${file/-iphonesimulator/-iphoneos}'"
rm -rf "${file/-iphonesimulator/-iphoneos}"
echo "[INFO] cp -r '${file}' '${file/-iphonesimulator/-iphoneos}'"
cp -r "${file}" "${file/-iphonesimulator/-iphoneos}"
done
echo '[INFO] Done! restart your Xcode'
@shaohuaguo
Copy link

run the script , but, Terminal return that

find: -regextype: unknown primary or operator

how to fix it?

@dnpp73
Copy link
Author

dnpp73 commented Apr 23, 2021

Thank you comment. I hadn't noticed this. The default find command on the Mac is the BSD version.
You can use GNU find. by brew install findutils. also you may need to set the PATH.

@shaohuaguo
Copy link

yes, it works. very very very very very thanks

Thank you comment. I hadn't noticed this. The default find command on the Mac is the BSD version.
You can use GNU find. by brew install findutils. also you may need to set the PATH.

yes, it works. very very very very very thanks

@simonwellchang
Copy link

run this sh,but show blow message,

[INFO] This workaround script is M1 Mac Only.

my macbook is M1 Pro Max

@dnpp73
Copy link
Author

dnpp73 commented Sep 30, 2022

@simonwellchang
Perhaps your terminal is running on Rosseta 2.
This workaround is for Xcode 12. It is no longer needed after Xcode 13.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment