Skip to main content

Configure SwiftUI Hot Reload

Syntax highlight & code completion

Install Zed swift extension

Install xcode-build-server

brew install xcode-build-server

Run in the project root dir, will generate buildServer.json:

xcode-build-server config -scheme <Project Scheme>

Install InjectionIII

InjectionIII settings

Xcode project settings:

Build Settings -> All -> Linking-General -> Other Linker Flags add -Xlinker -interposable

linker-setting.png

If >= Xcode 16.3, add User-Defined Setting EMIT_FRONTEND_COMMAND_LINES to YES, only in Debug is enough

user-customed.png

If run on a real device, such as a macOS app,

  • Turn off App Sandbox and Hardened Runtime in Signing & Capabilities signing.png

  • Set User Script Sandboxing to NO in Build Settings user-script.png

    warning

    Remember to turn on the above two when on release

    • Add Scripts in Build Phases add-script.png

      RESOURCES=/Applications/InjectionIII.app/Contents/Resources
      if [ -f "$RESOURCES/copy_bundle.sh" ]; then
      "$RESOURCES/copy_bundle.sh"
      fi
      • Add the code blew in App init method
        @main
        struct testApp: App {
        init() {
        #if DEBUG
        Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle")?.load()
        //for tvOS:
        Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/tvOSInjection.bundle")?.load()
        //Or for macOS:
        Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/macOSInjection.bundle")?.load()
        #endif
        }

        var body: some Scene {
        WindowGroup {
        ContentView()
        }
        }
        }

Develop SwiftUI App in other Editors

xcodebuild command line

Reference

// list project infomation
xcodebuild -list -project <Project Name>.xcodeproj

// build project debug
xcodebuild -scheme <Project Scheme> -configuration Debug

// run unit test
xcodebuild test -scheme <Project Scheme> -configuration Debug

// run unit test without build
xcodebuild test-without-building -scheme <Project Scheme>

Zed

tasks.json
[
{
"label": "Xcode Build & Run",
"command": "xcodebuild -scheme note-test -configuration Debug && open $(xcodebuild -scheme note-test -configuration Debug -showBuildSettings 2>/dev/null | grep -m 1 CONFIGURATION_BUILD_DIR | sed 's/.*= //')/note-test.app",
"use_new_terminal": false,
"reveal": "no_focus"
},
{
"label": "Xcode Build (Debug)",
"command": "xcodebuild -scheme note-test -configuration Debug",
"use_new_terminal": false,
"reveal": "no_focus"
},
{
"label": "Xcode Run",
"command": "open $(xcodebuild -scheme note-test -configuration Debug -showBuildSettings 2>/dev/null | grep -m 1 CONFIGURATION_BUILD_DIR | sed 's/.*= //')/note-test.app",
"use_new_terminal": false,
"reveal": "no_focus"
},
{
"label": "Xcode Stop",
"command": "pkill -x $(xcodebuild -scheme note-test -configuration Debug -showBuildSettings 2>/dev/null | grep '^ *PRODUCT_NAME =' | sed 's/.*= //')",
"use_new_terminal": false,
"reveal": "no_focus"
},
{
"label": "Xcode Test",
"command": "swift test",
"use_new_terminal": false,
"reveal": "no_focus"
}
]

Jetbrains

WIP