Last active
August 4, 2026 21:55
-
-
Save t0nghe/29cad0dbbfe3181113b3797f64d18af1 to your computer and use it in GitHub Desktop.
Hot reload, rebuild and update simulator on file changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -uo pipefail | |
| WATCH_PATH="<PROJECT_PATH>" | |
| RUN_SCRIPT="./run-simulator.sh" | |
| log() { | |
| printf '[dev %s] %s\n' "$(date '+%H:%M:%S')" "$1" | |
| } | |
| if ! command -v fswatch >/dev/null 2>&1; then | |
| log "Error: fswatch is not installed or is not on PATH." | |
| exit 1 | |
| fi | |
| if [[ ! -x "$RUN_SCRIPT" ]]; then | |
| log "Error: $RUN_SCRIPT is missing or is not executable." | |
| exit 1 | |
| fi | |
| trap 'log "Watcher stopped."; exit 0' INT TERM | |
| log "Watching $WATCH_PATH for source changes." | |
| log "Press Ctrl+C to stop." | |
| fswatch -o "$WATCH_PATH" | | |
| while read -r event_count; do | |
| log "Detected $event_count filesystem change event(s). Rebuilding…" | |
| if "$RUN_SCRIPT"; then | |
| log "Update completed. Waiting for more changes." | |
| else | |
| log "Update failed. Fix the error and save a file to retry." | |
| fi | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -uo pipefail | |
| PROJECT="<PROJECT_NAME>.xcodeproj" | |
| SCHEME="<SCHEME_NAME>" | |
| DERIVED_DATA_PATH=".build" | |
| APP_PATH="$DERIVED_DATA_PATH/Build/Products/Debug-iphonesimulator/<FILE_NAME>.app" | |
| BUNDLE_ID="<BUNDLE_ID>" | |
| log() { | |
| printf '[simulator %s] %s\n' "$(date '+%H:%M:%S')" "$1" | |
| } | |
| log "Checking for a booted simulator…" | |
| if ! xcrun simctl list devices booted; then | |
| log "Error: unable to communicate with Simulator." | |
| exit 1 | |
| fi | |
| log "Building scheme '$SCHEME' from $PROJECT ..." | |
| if ! xcodebuild \ | |
| -project "$PROJECT" \ | |
| -scheme "$SCHEME" \ | |
| -configuration Debug \ | |
| -destination 'generic/platform=iOS Simulator' \ | |
| -derivedDataPath "$DERIVED_DATA_PATH" \ | |
| build; then | |
| log "Build failed. The app was not installed." | |
| exit 1 | |
| fi | |
| if [[ ! -d "$APP_PATH" ]]; then | |
| log "Error: build succeeded, but the app was not found at $APP_PATH." | |
| exit 1 | |
| fi | |
| log "Build succeeded. Installing $APP_PATH ..." | |
| if ! xcrun simctl install booted "$APP_PATH"; then | |
| log "Installation failed. Confirm that a compatible simulator is booted." | |
| exit 1 | |
| fi | |
| log "Installation succeeded. Launching $BUNDLE_ID ..." | |
| if ! xcrun simctl launch --terminate-running-process booted "$BUNDLE_ID"; then | |
| log "Launch failed." | |
| exit 1 | |
| fi | |
| log "App launched successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment