Friday, May 26, 2023

Wallaroo and SwiftUI on macOS

Craig Hockenberry:

We have a View in the app that uses SceneKit to display a 3D scene with a confetti flourish after a customer starts a subscription. I was expecting stuff like that to take a lot of effort to get working on the Mac. Instead, it ran 100% out of the box with no modifications at all.

And the stuff that I was expecting to be easy, like a settings view, buttons, and menu commands, turned out to be hard. To put that “hard” in context, it took me about a month to go from an app that we were proud of on iOS to one that we were equally proud of on macOS[…]


We also found that many of the issues encountered on macOS were things we had done wrong on iOS. Porting the app to the Mac made both platforms better. We’re also rethinking our View architecture so things that are currently Mac-only can be used to improve the iPad experience.


You’re going to have platform-specific code. More than you realize: certainly more than I expected!


It took me three days to hook up a Save menu item and have it work reliably.

I don’t understand why they had to use a custom button style and a hard-coded radius to get buttons that looked good on both platforms. I thought the point of SwiftUI was that you’re supposed ot just specify that you want a button and it does the right thing on each platform.

Craig Hockenberry:

SwiftUI’s default mechanism for handling URLs on macOS isn’t great. If you’ve used .onOpenURL on a View to handle external events, you’ll be disappointed to learn that a URL scheme on macOS opens a new window (Scene) before it hands the URL to the view modifier. And if you’re using a single Window instead of a WindowGroup, nothing happens at all.


One thing we wanted to do was use the Escape key to pop the NavigationStack. On the Mac, it’s a key that has always represented “go back” and many apps (like Photos) take advantage of that. Unfortunately, to accomplish that in Wallaroo, we had to use an invisible ToolbarItem with a .keyboardShortcut(.escape, modifiers: []).


While you’re struggling with window and sidebar size constraints, you end up with UserDefaults for frames that have “fun” keys like "NSWindow Frame SwiftUI.(unknown context at $1acd3d768).SceneBridgeReader, SwiftUI.ModifiedContent>, SwiftUI._PreferenceWritingModifierSwiftUI.PreferredColorSchemeKey>, SwiftUI._EnvironmentKeyWritingModifier>>>>-1-AppWindow-1".

Craig Hockenberry (Mastodon):

You won’t realize how much you depend on SwiftUI previews until you start working on macOS.

Sometimes they kinda work, but more often than not you’ll get an endless spinner. When they do work, they’re not interactive (you have to use the selectable mode with the arrow icon).


The similarity of the key names makes this a hard lesson to learn. I looked at “aps-environment” and “” for hours before I realized they were different. After you add the one for macOS manually, everything is golden.


We weren’t able to get FileRepresentation working in a Transferable. Other applications can’t access a temporary file that’s created for the export. This feels like a sandbox problem that we couldn’t work around.


1 Comment RSS · Twitter · Mastodon

To learn SwiftUI I’d make a simple app like this. But it’s basically collection views of wallpapers. It’s kind of depressing to read. Everyone always enumerates all the problems and finishes off with high praise which I kind of find perplexing.

Shouldn’t Command [ be used to go back instead of the Escape key?

Does SwiftUI use mostly UIKit under the hood? It looks that way.

Leave a Comment