Catalyst in Big Sur
June 30, 2020
After initially opening Catalyst up to developers last year, for macOS Big Sur, Apple has spent a lot of time refining the framework to allow for the creation of better Mac apps. Let's take a look at the improvements in macOS Big Sur:
Optimized for Mac
Last year, Apple added the "Mac" checkbox to iOS projects in Xcode. This year, they added a dropdown next to that checkbox which allows you to choose between two different ways to build your Mac app: The default option (which was also the one all Catalyst apps had to use until now) is "Scale Interface to Match iPad". If you select this option, your entire app gets scaled to 77% to match the Mac's smaller UI style. The main benefit of this option is that all your layouts automatically work on the Mac. On the other hand, this scaling results in blurry text and images, which makes the app look a lot worse than one created with AppKit.
New this year is the second option in that dropdown named "Optimize
Interface for Mac". If you select this option, your UI won't be scaled
and standard UIKit controls, like UIButton
and
UISlider
, will look like their AppKit equivalents. The font
size of the standard text styles will be different, and Auto Layout's
system spacing will be larger.
This means your layout will probably break if run the app, but
if you take the time to fix the layout issues, your app will feel a lot
more Mac-like. When a Catalyst app runs in this mode, it uses the
Mac
user interface idiom. In your code, you can check for
this idiom:
if traitCollection.userInterfaceIdiom == .mac {
// Only on Mac
}
Code inside
#if targetEnvironment(macCatalyst) /* Only on Mac */ #endif
, will be executed in Catalyst no matter which user interface idiom is
used. Checking for the user interface idiom will allow you to
differentiate between the two Catalyst modes.
If you don't want to spend a lot of time on the Mac version of your app, the default option is an okay choice, but if you want to build a great Mac app, the second option is the way to go.
New iOS Frameworks
This year, a couple more iOS frameworks have come to the Mac. These
include ReplayKit, HomeKit, and ClassKit. In PencilKit,
PKCanvasView
is also finally interactive which means all
sorts of drawing apps can now come to the Mac.
Apple also added a bunch of dummy frameworks so that less code has to be removed when making Catalyst apps. These include HealthKit, CoreHaptics, and ARKit.
General UI
I already mentioned that it's now possible to make
UIButton
, UISlider
, UISwitch
, …
look like their AppKit counterparts.
As Steve Troughton-Smith pointed out, these controls don't just look
like AppKit controls but are actual AppKit ones.
Additionally, modal sheets are now their own resizable windows and
popovers don't have to stay inside the window borders anymore. The new
UIKit color well and tint color also translate to the Catalyst versions.
All of these additions allow for more optimization and the creation of
better Mac apps.
If that wasn't enough, NSCursor
is now exposed to Catalyst
apps. You can hide/unhide the cursor or set a cursor image.
With macOS Big Sur, toolbars have gotten a big upgrade1. Just
like in AppKit, you can now choose from a bunch of different
UITitlebarToolbarStyle
s:
windowScene.titlebar?.toolbarStyle = .unified
Which of the available toolbar styles makes the most sense for you depends on your usage, and I can only recommend reading the HIG on this topic.
If you are using a sidebar in your app, you can now also place toolbar items on the right side of that sidebar. This wasn't possible before since sidebars are resizable on macOS. An example of this can be seen in the new messages app on the "New Message" button. To achieve this effect, you can use this new toolbar item identifier in your default item identifiers.
UISceneCollectionJoinBehavior
now has a
collectionJoinBehavior
which allows you to specify if you want a window to be opened as a tab
or new window.
Conclusion
Catalyst has gotten a lot of (needed) implements in Big Sur. We've already seen a lot of Catalyst apps but not many that are actually good. I hope this changes over the next year since making a great Mac app doesn't require an unreasonable amount of effort anymore.
1 Disclosure: I'm obsessed with Mac toolbars. Last year, I spend most of WWDC week experimenting with Catalyst toolbars and trying to get them to work correctly.