In the introduction, you learned about what Catalyst is, how it works and the initial considerations you’ll make when using it to bring your app to the Mac.
In this chapter, you’re going to get your first look at the sample app that you’ll be interacting with in this book. Once you familiarize yourself with the basic functionality and architecture, you’ll take your first steps toward bringing the app to macOS.
By the end of this chapter, you’ll learn:
- The basic functionality and architecture of the sample app.
- The Xcode project changes needed to get your iOS app running on macOS.
- Which features Catalyst gives you for free when running on the Mac.
- Which features don’t work as well out-of-the-box.
It’s time to get comfortable with the sample app that’ll be your companion in this Catalytic journey.
The Sample App: Journalyst
Meet the last journaling app you’ll ever need; it’s called Journalyst and it has been designed from the ground-up to be the best way to chronicle your daily adventures. Start by taking it for a quick test drive.
Open Journalyst.xcodeproj from the starter project for this chapter in Xcode and then build and run.
You see the main journal entry list screen:
Here you can see all the journal entries you’ve created as well as an add button in the upper right that will add a new entry when tapped. Try tapping the add button a few times to see new entries get added to the list.
Next, tap any entry in the list to dive into the journal entry detail screen.
At the top of this screen, there is a text area where you can add the textual content for this entry. Below the text area, you’ll find a button that you can tap to add images. Finally, there is a Share button in the upper-right that, when tapped, will bring up the standard iOS activity view, allowing you to share the content. Spend a few moments tapping on the various controls, and then get ready to move on to the code.
In the Xcode project, expand the Journalyst group in the navigation pane. Once you do so, you’ll see a handful of groups that house the various architectural components that make up the app, alongside the standard files you’d expect in a new Xcode project.
Here’s a brief breakdown of the files:
- Entry: A class that represents a single journal entry in the app.
- EntryDataSource: A datasource class that works with table view to update its data.
- MainTableViewController: A table view controller that renders the journal entries list, which is the main screen of the app.
- EntryTableViewController: A table view controller that renders the detail screen for a single journal entry.
- EntryTableViewCell: A table view cell that represents a single journal entry on the main screen.
- ImageCollectionViewCell: A collection view cell that renders an image attachment in the image area of the single journal entry screen.
Take some time to dig into each of the above files so you can get a feel for the overall structure and data flow. The app is not overly complex, but it will serve as a great starting point for taking you through all the aspects of Catalyst.
Once you feel comfortable with the project, it’s time to take your first steps towards Mac-ifying your first app.
The iPad Checkbox
“Wait, what? Weren’t you migrating this app to run on the Mac? What’s this iPad business about?” You may have noticed that the Journalyst app is currently configured and designed to run on iPhone only. Well, it turns out that an iPhone app, even a great one, doesn’t translate well to the much larger screen of a Mac.
iPhone apps are optimized for single-window use, where you see one screen at a time on a very confined display size. They aren’t typically concerned with things like drag-and-drop, multi-tasking, split views, keyboard shortcuts and all manner of other functionality commonly found in Mac apps.
iPad apps, on the other hand, are concerned with the above features, run on comparable display sizes, and thus have far more in common with Mac apps. For this reason, Apple wisely decided that, for an iOS app to run on macOS, it must be capable of running on iPad. So if you were hoping to take your iPhone-only app straight to macOS, you’re in for a bit more work than you may have expected. This book will guide you through the process of both bringing your iPhone app to iPad, and then bringing that iPad app to the Mac.
Apple states that the first step in making a great Mac app using Catalyst is making a great iPad app. The more your app is designed to be a good citizen on the iPad, the easier it will be to bring it to macOS using Catalyst. So before you can check the “Mac” checkbox, you’ll have to check the “iPad” checkbox.
In the Xcode project, click the top-level Journalyst entry in the navigation pane, select the main app target, and click the General tab. You see three checkboxes within the Deployment Info section, only “iPhone” is currently activated.
Check the iPad checkbox. Just like that, you’ve added support for iPad. Select an iPad simulator as the run target then build and run to look at the fruits of your labors.
And there it is! The Journalyst app running on the iPad… Looks great right? Well, maybe not so much.
Through the magic of auto-layout, nothing looks broken per se, and app features still work. However, what you see is an inflated version of the iPhone app. It doesn’t look or feel like a first-class iPad citizen. You can do much better than this, and in the chapters that follow, you will.
Be aware that some features are downright broken when running on iPad. If you try to activate anything that would bring up an action sheet, such as adding an image or sharing an entry, the app will crash. You’ll learn why this is the case, and how to fix it in the next chapter.
But this chapter is all about instant gratification via checkboxes, so put your dreams of creating the next hit iPad app to the side for now and prepare to see the app running on the Mac.
The Mac Catalyst Checkbox
And now the checkbox you’ve been waiting for! Back in the General tab of the Journalist target settings, go ahead and check the Mac Catalyst checkbox.
You’ll notice that, this time, unlike when you checked the “iPad” checkbox, Xcode prompts you to make some changes to the project. Allow it to do so, and the following changes will be made:
- An entitlement for App Sandbox is added to the Journalyst.entitlements file. Apps that are distributed on the Mac App Store must incorporate sandboxing, which you’ll learn more about in a later chapter that covers distributing your Catalyst app.
- A new run destination for My Mac is added to the project so that you can run the app from Xcode.
- Incompatible frameworks, app extensions and other embedded content are excluded from the Mac build. In this case, there aren’t any yet.
Once you’ve enabled the Mac checkbox and accepted project changes, you’ll notice a new dropdown to the right of Mac Catalyst. Go ahead and click it, then select Optimize Interface for Mac.
From Apple’s Xcode 12.2 release notes on the option:
When bringing iPad apps to macOS, you can now use the Optimize Interface for Mac target setting to use native macOS controls and Mac resolution.
Since your ultimate goal is to make an app that looks and feels like a first-class macOS app when running on the Mac, you want the interface to be optimized accordingly.
Go to the Signing & Capabilities tab of the Journalyst target settings and under Signing, you’ll notice you have bundle ids for iOS and Mac Catalyst platforms. Under the Mac Catalyst platform, you’ll notice Use iOS Bundle Identifier is checked.
Go ahead and uncheck the Use iOS Bundle Identifier checkbox. Then, create a Mac Catalyst bundle identifier as maccatalyst.com.yourcompany.Journalyst.
This makes sure the app you are running uses a different bundle identifier on macOS, allowing you to separately control and price your macOS app in the App Store, or distribute your macOS app outside the App Store.
The last thing you’ll need to do before running the Mac app is to specify code signing information. This step isn’t necessary when running the iOS app on simulators, but in this case, your Mac is a real device, so the bundle needs to be signed.
Go ahead and select a team. Make sure Automatically Manage Signing is enabled, and Xcode will take care of the rest.
Finally, change the run destination to My Mac, build and run, then bask in the glory that is your first Catalyst app!
Much like when you ran the app on iPad for the first time, the basic functionality is there after applying almost zero effort, but the app in its current form leaves much to be desired. Still, Catalyst gives you a whole lot of Mac goodness for free, so poke around, and you’ll find that your Mac app already has the following features:
- A basic Mac menu bar.
- Support for trackpad, mouse and keyboard input.
- Support for window resizing and full-screen display.
- Mac-style scroll bars.
- Copy-and-paste support.
- Basic drag-and-drop support.
- Support for system Touch Bar controls.
But it’s not all rainbows and checkboxes at this point — there’s still a lot of work you’ll need to do to make this app a first-class Mac experience. Some of the more notable features that are currently missing are:
- Multi-window support.
- A better navigation structure, given the larger screen size (a split view would do nicely here).
- Extended drag-and-drop support for things like dragging images into journal entries.
- Extended keyboard support for things like shortcuts.
- Extended mouse support for custom contextual menus.
- A Mac-style preferences window for app settings.
- A better look and feel for the app that aligns it more with what you commonly see on macOS.
- Better support for the menu bar, toolbar and the touch bar that go beyond what you get out-of-the-box.
That list might look daunting, but the remainder of this book guides you through the process of implementing all these features and more. The rest of the chapters in Section 1 covers the features that you’ll add to turn Journalyst into a great iPad app. Section 2 then covers the process of turning your great iPad app into an even greater Mac app. Rounding things out, Section 3 walks you through the finer points of testing using TestFlight, packaging and distributing your new Mac app.
- Journalyst is a basic journaling app that you’ll be improving throughout this book.
- Before you can make a great Mac app using Catalyst, you need to make a great iPad app.
- Catalyst gives you plenty of Mac functionality for free.
- To make a truly great Mac app using Catalyst, you need to go above and beyond what comes out-of-the-box, covered above.
Where to Go From Here?
In this chapter, you became familiar with Journalyst, the sample app of this book, as you learn how to bring apps from iPhone to iPad, and then to the Mac. You took the first steps along this path by configuring the app to run on both iPad and Mac by changing the Xcode project configuration. Finally, you learned about which features Catalyst provides out of the box and which ones require additional effort to enable.