Using UIKitForMac, it is finally possible to bring your existing iPad apps to the Mac. When making your app available on macOS, you can target a new platform with more than 100 million active installs.
The reason iPad apps can now run on the Mac, is that Apple added support for UIKit in macOS Catalina. UIKit is the framework that allows you to style your app using a rich set of UI elements. In the past, macOS apps could only be build using AppKit, another UI framework. Now macOS is supporting UIKit, developers can really easy bring their apps to the Mac App Store.
Not all apps are useful on macOS, like navigation apps. Also, apps that use augmented reality are not useful on macOS, because the technique is not available in Macs. For this reason, Apple didn’t bring the ARKit framework for Mac.
Build your iPad app for macOS
Apple made it easy for developers to run existing iPad apps on the Mac. To start, open your project in Xcode 11 and go to the settings of your app. Then, on the “General” tab, you will find the new option “Mac” as deployment target. Just enable the checkbox and you’re ready to run your app on macOS!
When clicking the deployment checkbox “Mac”, Apple will arrange some processes for you:
- Adds a bundle identifier for the Mac version of your app.
- Adds the App Sandbox Entitlement to your project.
- Xcode includes this entitlement in the Mac version of your app, but not in the iOS version. Adds My Mac to the list of destinations that you can choose when running your app from Xcode.
- Excludes incompatible frameworks, app extensions, and other embedded content.
To submit an app for macOS, you need to create a new app in the App Store Connect portal. This is because macOS apps have a different bundle identifier.
⚠ Current status: Beta!
Currently UIKitForMac is in beta, which means not all frameworks and SDKs are already optimized for macOS. Because of this, you may need to disable some frameworks or uncomment some code.
Issues I found during my research:
1. Frameworks like Crashlytics and Firebase are not running. They need an iOS simulator for compiling code. Simply uncomment this part of code and disable the frameworks for your macOS build.
2. Some frameworks are also available for macOS, like Kingfisher. SDKs can contain #if canImport(Appkit) code. Xcode will compile this code, because AppKit is available for the macOS target. Simply uncomment this part of code to let your app compile.
Disable functionalities for macOS
There may be functionalities in your app that are excellent for iOS or iPadOS but are useless on macOS. It is easy to disable this code for macOS using a target environment check.
Example to exclude functionalities for macOS:
#if !targetEnvironment(UIKitForMac) // Code to exclude for your macOS app #endif
Using the code above, it’s possible to exclude code for macOS. If you want to add functionalities only for your macOS app, you can use the same check, but then without the exclamation mark.
Example to add functionalities for macOS:
#if targetEnvironment(UIKitForMac) // Code to include in your macOS app #endif
Add support for the macOS menu bar
Bringing your iPad app to macOS makes your app already look and feel like a macOS app, but there are some improvements you can add to integrate better with the macOS operating system. One of the core functionalities that can be added, is support for the menu bar.
At WWDC, Apple announced UIKeyCommand, which enables support for menu bar. However, UIKeyCommand is already deprecated for now. When Apple did make a final decision how developers can add support for the menu bar, I will update this article.
Add support for drag and drop
One of the main functionalities for computers is dragging and dropping content. Supporting this in your macOS apps is easy, by integrating the UIDragInteraction and UIDropInteraction instances.
Drag and drop was announced during WWDC 2017 and is available for iOS 11 or higher. If you already added support for drag and drop in the past, your macOS app will automatically support drag and drop!
To get an introduction to drag and drop, I recommend to watch the WWDC session of 2017, Introducing Drag and Drop. This talk by Apple will bring you quickly up to speed with the drag and drop API.
By default, the app icon you’re using for your iPadOS app, will be used for your macOS app. However, app icons for macOS look slightly different. For this reason, you can set a specific app icon for macOS by enabling the Mac checkbox at your AppIcon in the Assets folder.
UIKitForMac is an awesome way to build apps for the Mac. If you already maintain an iPad app, you can bring your app to the Mac with very less effort.
Apple also provides APIs to make your app integrate better with macOS, by adding support for the menu bar, touch bar and other macOS specific functionalities. By adding support for those functionalities, users will love your Mac apps!
For more information about UIKitForMac, I recommend you to read the Catalyst Complete Book, written by Benedikt Terhechte. Also watch the session “Taking iPad Apps for Mac to the Next Level” from WWDC 2019, to get an overview of all the possible integrations with macOS functionalities.
🚀 Like this article? Follow me on Twitter for more macOS related news!