1

Environment: Mac mini M1; and
iPhone 6s Plus, etc.
macOS 11+, iOS 14+

I'm using SwiftUI/Combine Frameworks versus Storyboard.

Scenario: I have an iOS application that I want to expand into a macOS sister application;
and probably add more functionality too.

I assume that 'Mac Catalyst' is an option on the iOS side to map it to the macOS environment without hassle with the code.

I also assume that from this baseline, I could create a macOS target and share common code between the two and add compiler directives to separate the macOS & iOS specifics.

Am I correct?

HangarRash
  • 7,314
  • 5
  • 5
  • 32
Frederick C. Lee
  • 9,019
  • 17
  • 64
  • 105

1 Answers1

3

Given an iOS target that is Catalyst enabled (eg the "Mac" checkbox checked), you can use any frameworks/functions marked as available in iOS and Catalyst.

You can also conditionally compile for the different systems using things like:

#if targetEnvironment(macCatalyst)

or various @available configurations (https://nshipster.com/available/).

If your question is whether you can use macOS-specific code (not marked as available in Catalyst), like AppKit, for example, the question becomes more complicated. One can import and use a bundle with AppKit code, but it's not what I would call a streamlined process. See: https://www.highcaffeinecontent.com/blog/20190607-Beyond-the-Checkbox-with-Catalyst-and-AppKit

jnpdx
  • 45,847
  • 6
  • 64
  • 94
  • The link focuses on AppKit vs SwiftUI/Combine. One of the neat things about SwiftUI is that the pure code is usable in both platforms. I'll toy with the possibility on enhancing the MacOS portion via the bundle. Thanks. – Frederick C. Lee Mar 30 '21 at 01:00
  • The "pure code" *may* be usable on both platforms. There are lots of 'gotchas' with significantly different functionality between the two. I have two apps in the App Store on both platforms -- one with Catalyst and one without. If I had to do it over again, I'd probably avoid Catalyst. – jnpdx Mar 30 '21 at 01:02
  • 'Avoid Catalyst' -- why? --- I suppose you wouldn't need catalyst if you already have support for OS X. – Frederick C. Lee Mar 31 '21 at 01:26
  • There are a whole bunch of bugs that only occur in Catalyst, specifically relating to clicking behavior. See: https://stackoverflow.com/questions/65996725/swiftui-controls-dont-respond-to-input-clicks-in-catalyst-if-revealed-in-scro – jnpdx Mar 31 '21 at 01:44
  • Wow. Okay. I'll avoid Catalyst; I don't need it anyway. – Frederick C. Lee Mar 31 '21 at 01:46