Post

Replies

Boosts

Views

Activity

Reply to SwiftUI debug preview attach failed (Not allowed to attach to process
When running a preview on an app target, the target is used as the preview's host. When running a preview on non-app targets, Xcode is using XCPreviewAgent as the host. The problem is that XCPreviewAgent process does not allow debugging. But we can workaround this. The XCPreviewAgent is just a dummy iOS app without any logic, so we can create our own app with same name and bundle identifier, build it with debug capabilities and install it on the simulator used for running the preview. To do that, first install the app on normal simulator by running the app, then copy the bundle to the preview simulator (you can find the path by checking the issue report in Xcode's preview canvas). After that we will be able to attach debugger to now our custom XCPreviewAgent and debug our previews. I'm using this hack to develop SwifUI views in isolation as a separate Swift Package without a real need for a project file. Running SwiftUI previews on the main app is very inefficient as the whole project has to be rebuilt every time you run a preview.
Sep ’21
Reply to SwiftUI Preview triggers test target build
It is still an issue in the Xcode 14.2 and is very annoying. More to that, the SwiftUI Previews build does not run Swift Package build plugins, making the test target build failing if it relies on those. One has to first build the target for testing to trigger the package plugins, then the previews start working.
Feb ’23
Reply to Code signing generated with wrong version
Just stumbled upon this issue when using an XCFramework Swift package and found a solution. To enforce a specific code signing version you need to use two extra command line options: -o, --options flag,... During signing, specifies a set of option flags to be embedded in the code signature. The value takes the form of a comma-separated list of names (with no spaces). Alternatively, a numeric value can be used to directly specify the option mask (CodeDirectory flag word). See OPTION FLAGS below. --runtime-version version During signing, when the runtime OPTION FLAG is set, explicitly specify the hardened runtime version stored in the code signature. If this option is omitted, but the runtime OPTION FLAG is set then the hardened runtime version is omitted for non-Mach-O files and derived from the SDK version of Mach-O files. Adding the following options will result in a v=20500: runtime --runtime-version "16.4.0" After this the app successfully installs on a device. You can add those option to the OTHER_CODE_SIGN_FLAGS in the Build Settings of your app target.
May ’23
Reply to Xcode 12.5 "code signature version is no longer supported"
Found a workaround and described it in this thread. TL;DR Adding the following options to the codesign command will result in a v=20500: -o runtime --runtime-version "16.4.0" So the solution would be adding those options to the OTHER_CODE_SIGN_FLAGS in the Build Settings of your app target, e.g.: -o runtime --runtime-version $DEPLOYMENT_TARGET After this the app successfully installs on a device.
May ’23