Mac Catalyst: Seamlessly Extending Your iOS Apps to macOS

Afsanafarheen
5 min readMay 22, 2023

--

With the introduction of Mac Catalyst, Apple has provided a powerful toolset that allows developers to bring their iOS apps to macOS with relative ease. This groundbreaking technology bridges the gap between iOS and macOS, enabling developers to leverage their existing iOS codebase and expand their reach to Mac users. In this blog post, we will explore the world of Mac Catalyst, its benefits, and how it empowers developers to unlock new possibilities in cross-platform app development.

Create a new project in Xcode and name is as Recipe Application, we are going to use the sample project given by apple to understand Mac Catalyst. In this blog I will be focusing more about the setup and implementation of Mac Catalyst.

After creating a new project , In the Project navigator, select the project to view the Project editor

By default, iPhone, iPad and Mac is set as the ”Supported Destination”. Now, we are going to remove “Mac” and then add “Mac Catalyst” instead.

After removing Mac, when you click “+” you will get the options like shown in the image. Select “Mac Catalyst”and then you will get a alert like this. Click “Enable”.

Now go to “Deployment info” and you should see a option like this :

In Xcode, under the “Deployment Info” section, the “Mac Catalyst” interface option allows you to specify the interface style for your Mac Catalyst app.

There are two types of interface here:

Scaled to match iPad:

Scaled version is used when you are planning to use the exact interface of iPad to adapt in Mac. By the name itself we can understand that it is the scaled version of iPad’s UI. The layout, size, and proportions will be preserved, providing a consistent experience across platforms. However, customisation for the Mac platform may be limited, and some views might appear smaller or cramped when displayed in the expanded view.

Optimised for Mac:

Optimising for Mac gives you Mac-like visuals and controls that aren’t available to Catalyst apps scaled to match the iPad. It provides more control over the layout and design, allowing you to adapt the app to macOS design principles and take advantage of Mac-specific features. This option ensures a more native and tailored experience for Mac users, although it may require additional development and design effort.

Profile setup:

  1. Go to the “Sign in and Capabilities” tab.
  2. Within the iOS section, you will find a macOS column. Click on it.
  3. Add the Mac development profile by clicking the “+” button or selecting an existing profile if you have one.
  4. Make sure the bundle identifier for the Mac development profile matches the bundle identifier used for iOS.
  5. If you don’t have a development profile, you can use the “run locally” option to run the application without a profile.
  6. With the setup complete, select the Mac target in the simulator.
  7. Run the application, and it will launch in the Mac simulator.

Mac-specific implementation:

Let’s say we choose “scaled to match iPad” there might be some view which might not work or might look smaller in Mac or you might want to show a pop sheet in Mac which presents in iPad. Hence to achieve this we have write code that should work only for Mac.

The below code can be used to identify if the device is Mac, and we can put our Mac-specific changes within it.

#if targetEnvironment(macCatalyst)
//write your code
#endif

Mac-Specific Code in a Unified iOS and macOS Project

It is possible compile a dedicated controller or Swift file specifically for the Mac platform within a single project that supports both iOS and macOS.

To create a dedicated controller or Swift file that is specific to Mac, you can follow these steps to ensure it compiles only for the Mac platform:

  1. Go to the “Build Phases” tab.
  2. Under the “Compile Sources” section, locate the files you want to make Mac-specific.
  3. Select the desired files, and in the right-hand panel, you will find a list of available options.
  4. Look for the “Mac Catalyst” option under the “Filters” column.
  5. Check the box next to “Mac Catalyst” for the files you want to compile only for Mac.
  6. Make sure to leave the box unchecked for the files that should be available on both iOS and Mac.

Now you can effectively utilise the same project for both iOS and macOS without the need to maintain separate projects. This approach allows you to isolate Mac-specific code and ensure it is only compiled for the Mac platform.

“Scaled to Match iPad” — Maintaining the Original iPad Layout on macOS

When you choose the “Scaled to match iPad” option in Xcode for a Mac Catalyst project, all the elements within your app will appear exactly as they do on an iPad. This means that the user interface will maintain its original layout, size, and proportions, without any modifications specific to the Mac platform.

However, it’s important to note that the “Scaled to match iPad” option does not provide the flexibility to customize the layout or expand columns in the Split View. This means that some views might appear smaller or cramped when displayed in the expanded view, as it is essentially an enlarged version of the iPad interface.

“Optimise for Mac” — Customising the User Interface for macOS

When you enable the “Optimise for Mac” option in Xcode, it allows your UIKit elements, which are typically designed for iPadOS or iOS, to adapt and provide a more Mac-like experience. Apple provides a sample project that demonstrates how UIKit elements adapt when this option is used. You can check the project here.

By utilising the “Optimize for Mac” feature, you can leverage the flexibility of UIKit to automatically adjust the appearance and behavior of your app’s user interface when running on macOS. This enables your app to feel more native to the Mac platform while still maintaining a unified codebase.

UIMenu behavior in mac vs ipad.

Hope this article was helpful 😄.

Follow me on twitter : https://twitter.com/iamafsana_
Buy me coffee

Sayonara!! 😃

--

--

Afsanafarheen

I'm Afsana Farheen, an experienced iOS developer with a passion for creating innovative and user-friendly mobile applications.