Adding macOS Support to an iOS App: My Experience with Piqt
If you plan well, porting your iOS app to macOS is pretty seamless. But there are gotchas that bit me, and they could bite you too.
This month I launched Piqt 1.2, which adds a macOS version. It shipped only a month after my previous significant release, and I was amazed that the port took so little time. That’s a testament to the portability of Swift and SwiftUI in the Apple ecosystem. It’s the same SwiftUI codebase as the iPhone and iPad versions, with a real sidebar, menus, keyboard control, and grids that fill a big screen. Getting it up and running was surprisingly fast and easy.
However, if you dig into how I spent that time, 10% of it was getting to a functional app and 90% of it was fixing hairy Mac-specific bugs. As always, that last step is a doozy. This post is for other developers taking a SwiftUI iPhone app to the Mac: the kinds of problems that cost me days, and how I’d diagnose them next time.
Getting it running: well, that was easy
Once I started working on the Mac app, I had it up and running almost immediately. Part of this was planning. I knew I would release a Mac app eventually, so very early in Piqt development I made a rule: macOS must compile and run before I could release. I focused on iOS for the original launch, but that check meant I never built up a backlog of iOS-only code that I’d need to exclude on the Mac.
So when it was time to start the Mac port in earnest, I already had a running app. There were a few failing tests and a few features without a Mac analog yet, but that work was quick. I had Piqt running and passing tests on the Mac on day 2.
Lesson: if you’re ever going to launch on Mac, get it building now and keep it building. As you’ll see below, checking once per release turned out not to be often enough.
The other 90%
Looking back, almost every Mac bug I hit fell into one of five kinds. What they have in common is that most of them don’t crash. The Mac falls back to some default and keeps going, and the app looks close enough that you don’t notice. That’s what makes them expensive.
1. Silent fallbacks
The features on the Mac build were mostly identical, but I built Mac-specific layouts (a persistent sidebar, configurable grids, denser trip and dupes views) to take advantage of the larger screen. Everything compiled, and the spot checks looked fine. But when I looked closer, most of my changes were not showing up. I assumed it was my layout code, and spent a while tweaking constraints that weren’t even being used.
The real cause was a footgun I’d placed myself when I added iPad support. Piqt has its own size-class resolver, because Apple’s two size classes don’t describe enough: the layout depends on iPad model, orientation, and split-screen width, not just “compact or regular.” The resolver took the device type as two yes/no flags:
static func resolve(isPadIdiom: Bool, isPhoneIdiom: Bool = false, width: CGFloat, ...) -> PiqtSizeClass {
guard isPadIdiom else {
return (isPhoneIdiom && width > height) ? .phoneLandscape : .phone
}
// ... iPad breakpoints by width
}
The flags came from UIDevice.current.userInterfaceIdiom. A native macOS app has no UIKit, so on the Mac both flags were simply false, and “not an iPad” fell through to .phone. The Mac window was rendering the iPhone app at a larger size, and nothing crashed or logged. (UIUserInterfaceIdiom does have a .mac case, but it only applies to Mac Catalyst apps, not native SwiftUI ones.)
The fix that actually prevents this is to stop describing the platform as booleans with defaults. Booleans let you represent impossible states (“phone and iPad”) and they let a new platform quietly answer “no” to everything. An enum with a switch doesn’t:
enum PiqtPlatform { case phone, pad, mac }
static func resolve(platform: PiqtPlatform, width: CGFloat, ...) -> PiqtSizeClass {
switch platform {
case .mac: // content-column width → iPad breakpoints
case .pad: // size class + width → iPad breakpoints
case .phone: // aspect → portrait or landscape
}
}
The platform is decided once, in one place, behind one #if os(macOS). If I’d written it this way to begin with, adding the Mac would have been a compile error until I gave it a layout.
Two more bugs had the same shape:
- Network was off. The Mac target had App Sandbox on with outgoing connections disabled. Telemetry quietly stopped, the feedback board failed, and CloudKit sync would have broken entirely. One entitlement fixed all three.
- A keychain password prompt on every launch. The Mac target had no development team set, so every debug build was ad-hoc signed and looked like a different app to the keychain. Signing with a real team fixed it.
How to diagnose: any code that branches on platform or idiom has a Mac answer, whether you wrote one or not. Search for UIKit to find every place your app reaches into iOS-only code. The compiler already catches any UIKit use you forgot to guard. The dangerous ones are the guarded ones, wrapped in #if os(iOS) or #if canImport(UIKit), because they compile fine and the Mac quietly gets whatever the #else says, or nothing at all. For each one, ask what the Mac actually gets; anywhere the answer is “whatever the default is,” make the Mac an explicit case. Log the values your app resolves at launch (size class, platform, which features are enabled) and read them once on the Mac. Then compare the Mac target’s entitlements and signing settings against iOS line by line. None of this takes long, and any of it would have saved me days.
2. Same API, different host
On the Mac, your SwiftUI views are hosted inside AppKit, and some APIs behave differently there even though the code is identical. These are the hardest bugs, because the code looks correct, is correct according to the docs, and works correctly on iPhone.
The most frustrating one for me was when clicking a video in a grid froze the window. Rainbow spinner, force quit. The grids pushed the video detail with navigationDestination(item:), which works fine on iPhone and iPad. On the Mac, Piqt’s navigation stack sits in the detail column of a NavigationSplitView, and there the navigation request never got consumed. SwiftUI put it back in the queue on every render, each render invalidated the layout, and AppKit’s loop guard eventually threw. A day later, typing in a search field froze the window the same way, this time because destinations registered in a pushed view were being re-checked on every layout pass.
This one is tricky because I know what happens (I watched it in backtraces), but I don’t know why the Mac’s split view behaves differently from iOS. It isn’t documented, and it may simply be a SwiftUI bug. What I did was find the pattern that triggers it and work around it: on the Mac, register navigation destinations only at the root of the stack, and present detail views inline instead of pushing them by item.
In my hunt to resolve this one, I fixed four other things first, but none of them did the job. A sidebar List whose headers never settled their layout, a view that wrote to state on every geometry change, a video player that took over the whole column, and some suspicious progress spinners were each a real layout loop with its own console evidence, and I kept the fixes. They just weren’t the one freezing the window when I clicked a video. I’d been fixing loops I could see instead of proving which one I had.
How to diagnose a frozen window:
Most SwiftUI freezes on the Mac are the same thing underneath: something writes state during layout, that write triggers another layout, and the loop never settles. The trigger varies. The way to find it doesn’t.
- Read the console first. AppKit’s loop guard (“needing another Update Constraints in Window pass … more passes than there are views in the window”) tells you it’s a layout loop rather than a deadlock or slow work. SwiftUI’s “tried to update multiple times per frame” next to it means state is changing mid-layout.
- Stop on the exception. A symbolic breakpoint on
objc_exception_throwcatches the loop guard when it throws. - If there’s no exception, pause it. Hit pause in Xcode (or
process interruptin lldb) while it’s spinning and read the main thread’s backtrace. Whatever repeats is your loop. - Find the writer, not the victim. The backtrace at the exception shows layout, which is the victim. You want whoever changed state. If you use
@Observable, a breakpoint on the Observation framework’swillSetstops on every state write; the one coming from inside layout is your culprit. - Make it reproducible without clicking. A small DEBUG-only hook that jumps to a given screen at launch turns a five-minute repro into a few seconds, and lets you set breakpoints before the trigger.
- Prove it before you fix it. Revert your fix and check that the bug comes back. My four “fixes” would all have failed that test for the video freeze.
3. Compile drift
My day-to-day test loop runs on the iPhone simulator, which means the Mac target doesn’t compile unless I build it on purpose. Checking at release time kept the backlog small, but between releases the Mac build broke silently at least four times. Almost all of the breaks looked the same: a helper was marked iOS-only and the code calling it wasn’t. iOS-only modifiers like .toolbar(.hidden, for: .navigationBar) were the usual culprit, and the fix was a small cross-platform wrapper that hides the #if inside it. The sneakiest was @available(iOS 27, *). The * means “every other platform, back to its deployment target,” so it quietly promised the Mac APIs that only exist on macOS 27.
How to diagnose: build for “My Mac” after any change that touches UIKit, an iOS-only modifier, or an @available(iOS ...) annotation. And watch the build time. A Mac build of Piqt takes about 15 seconds; twice I got a “successful” build in under a second that hadn’t compiled anything. If a build is suspiciously fast, touch the changed files and build again.
4. Platform conventions
Some things compiled and ran fine but felt wrong, because the Mac has different habits than the iPhone:
- Focus is often nil. SwiftUI’s built-in way to connect menus to views is
@FocusedValue, but on the Mac it goes nil whenever nothing has key focus, which is surprisingly often. That means menus that work only sometimes. Instead, menu items post to a small command bus, and the bus delivers each command to whichever window is key. Focus doesn’t matter, and with several windows open, a command reaches exactly one of them. - Shortcuts collide with typing. Piqt’s grids use single keys (F to favorite, Space for Quick Look). Putting those same keys on menu items would fire them inside every text field, including search. They stay as grid key handlers only.
- Windows come back the way you left them. An Xcode-launched debug build sometimes opened with no window at all. That’s macOS window restoration: a session that quit with no window restores none. Passing
-ApplePersistenceIgnoreState YESas a launch argument gives you a fresh window every time.
How to diagnose: use the app the way a Mac user would. Keyboard only for a while, menus instead of buttons, multiple windows, quit and relaunch. Most of these showed up in the first ten minutes of doing that.
5. Different numbers
The core algorithms for Piqt were completely unchanged, and all but one gave the same results on the Mac the first time. Piqt measures sharpness with a Laplacian variance, and the same photos scored about 23% apart at the median between the Mac and the iPhone. In practice only about 0.1% of blur flags changed, and iCloud sync makes it moot, since the first device to scan a photo shares its scores with the others. How that works is the subject of an upcoming post.
How to diagnose: if your app computes anything numeric from images, audio, or models, score the same inputs on both platforms and compare before you assume thresholds carry over.
Make the fixes stick
The rules above are easy to forget, so the important ones are tests now. One scans the source and fails if a navigation pattern that freezes the Mac shows up outside the safe helper. Another checks every keychain query. As of 1.2, the full test suite has to pass on the Mac too, not only the simulator.
The navigation guard earned its keep right away. While the Mac branch was in progress, I shipped an iPhone hotfix that added two new pushes using the exact pattern that freezes the Mac. That branch had never seen the Mac work, so nothing flagged it. When I rebased the Mac branch on top, the freeze was back in two places. Now the test catches it.
That’s the general lesson: iPhone work will keep reintroducing Mac bugs, because the iPhone is where I (and maybe you) test. Every Mac fix that matters should leave a test behind.
Try it
Piqt for Mac requires macOS 15 or later, and it’s the same app as on iPhone and iPad, so you don’t buy it twice. The Mac app shares all of the key features of the iPhone and iPad versions, with some enhancements for the big screen. Read about it in the release post.