Six Mac app bugs with one-line causes
Most of the bugs in Purrchiver’s history took real work to fix. These six didn’t. Each had a cause you could point to in a single line of a project file, a plist, or a view, and each was confusing until I found that line. They’re in the order they happened.
1. Automatic signing plus a manual identity: “conflicting provisioning settings”
My first Release archive failed with an error that the target had
conflicting provisioning settings. The target used automatic signing
(CODE_SIGN_STYLE = Automatic), but its Release configuration also
hard-coded CODE_SIGN_IDENTITY[sdk=macosx*] = "Apple Distribution". That
line was left over from an earlier setup that needed it.
Automatic signing already picks a Development identity for running and
Distribution for archiving. Pinning the identity by hand contradicts it,
and Xcode refuses to choose. Deleting the manual line fixed the archive. If
you use automatic signing, search your build settings for any leftover
CODE_SIGN_IDENTITY overrides.
2. Two window delegates forwarding to each other: a 34,828-frame crash
Purrchiver attaches a small SwiftUI helper to each window. It sets itself as
window.delegate and forwards anything it doesn’t handle to the delegate it
replaced, through responds(to:) and forwardingTarget(for:). The install
code looked harmless:
if window.delegate !== coordinator {
coordinator.previousDelegate = window.delegate
window.delegate = coordinator
}When two helpers were attached to the same window, the sequence went like
this. A installs over the original delegate. B installs and saves A. Then A
runs again, sees it’s no longer the delegate, and saves B. Now A forwards to
B and B forwards to A. The next time AppKit asked whether the delegate
responded to a selector, the two called each other until the stack ran out.
The crash report was about 34,828 frames deep in responds(to:). It showed
up during UI-test screenshot capture, which runs window updates back to back.
The fix: when the current delegate is already one of these helpers, take its saved delegate instead of chaining through it, so the chain stays linear:
if let other = window.delegate as? Coordinator {
coordinator.previousDelegate = other.previousDelegate
} else {
coordinator.previousDelegate = window.delegate
}As a backstop, forwarding now stops if the saved delegate is itself one of these helpers. Two unit tests build the cycle on purpose. Without the fix they would crash; with it they return immediately.
3. Exporting types you don’t own
To open .7z, .rar, .bz2, and similar files, Purrchiver’s Info.plist
declares their uniform type identifiers. Six of them, including org.7-zip.*
and com.rarlab.*, were under UTExportedTypeDeclarations. Exporting a type
claims to be its owner. When another installed app also declares the same
identifier, which declaration Launch Services uses can depend on what else is
installed and in what order.
Types you don’t own belong under UTImportedTypeDeclarations. The fix was
literally three lines: close the exported array after Purrchiver’s own
com.coreydaley.purrchiver.* types, and open an imported array for the
rest. A unit test now reads the built Info.plist and fails if any exported
identifier lacks the app’s own prefix.
4. Unbalanced NSCursor push and pop: a stuck pointing hand
Two hover-highlight buttons managed the cursor inline:
.onHover { hovering in
if hovering { NSCursor.pointingHand.push() } else { NSCursor.pop() }
}That code has two bugs. The else pops unconditionally, so a hover exit
without a matching push pops a cursor some other view pushed. Worse, a view
that’s removed while the pointer is over it never gets onHover(false). Its
push is never undone, and the pointing hand stays stuck everywhere,
including over controls that have nothing to do with it.
Both buttons now use one shared modifier. It tracks whether it pushed, only
pops its own push, and pops in onDisappear too:
.onHover { apply(shouldPush: $0 && isEnabled) }
.onDisappear { apply(shouldPush: false) }
// push only if we haven't; pop only if we didThe push/pop decision is a pure function, so four small tests cover every transition.
5. A synchronized folder shipped the StoreKit test config
Xcode’s folder-synchronized groups make every file in a folder a member of
the target. That’s convenient until a test-only file lives in the app’s
folder. Purrchiver’s local StoreKit configuration file, Products.storekit,
was in the app folder, so it was copied into Contents/Resources of every
build, Release included.
It did nothing at runtime, because the shipping app uses the real App Store.
But it’s a development file, and it doesn’t belong in the bundle. Moving its
target membership to the test target alone fixed it, and the tests that use
it still find it there. (The rest of that StoreKit work is in
A StoreKit 2 one-time unlock with no server.) After any project reorganization, check what actually
lands in Contents/Resources.
6. A .gitignore rule that ate a vendored library
Purrchiver’s age support is a Rust library shipped as a prebuilt
.xcframework. When I moved the engine packages into the app repository, the
app’s .gitignore had a rule left over from earlier:
*.xcframeworkgit add on the parent directory skips ignored paths without a warning, so
the static library inside the framework was never staged. My working copy
built fine because the file was on disk. A fresh clone would have failed to
link. The fix is a negation for the one artifact that should be committed:
*.xcframework
!Vendor/libfoo.xcframeworkRun git status --ignored after moving vendored binaries between
repositories. It shows what your rules are silently swallowing.
The common thread
None of these were logic bugs. Each was a declaration that said something slightly different from what I meant: a signing setting, a delegate pointer, a plist key, a cursor stack, a folder membership, an ignore rule. The compiler can’t catch that kind of mistake. A small test or a check of the built product usually can, and most of these now have one.