UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Identify what OS the app is running on

Forums > SwiftUI

I have an app that running in Catalyst and also on iOS.

I want certain features not to be available on MacOS (Catalyst), but I can't seem to identify when the app is running on a Mac. The following code reports the OS as iOS when running on the Mac.

#if os(iOS)
print("OS is iOS")
#elseif os(macOS)
print("OS is MacOS")
#elseif os(watchOS)
print("OS is watchOS")
#elseif os(tvOS)
print("OS is tvOS")

To some degree I can understand why this is happening, but all said, the reported OS should be MacOS.

Does anyone have an idea as to how I can determine when the app is running on a Mac?

BTW, kinda related but when I use Testflight to distrubute the app, the email invite only mentions iOS (it says something like "Install Testflight for iOS") but clicking the links on a Mac allows you to install Testflight on Mac too. The email is misleading and does not make for a great UX for the beta tester who wants to test the app on a Mac.

Any advice here folks?

Thanks very much!


ProcessInfo can tell you if it is a Catalyst app, it can also get the display version or numeric version of the operating system.


I'm fairly new to Swift and SwiftUI, but those look like compiler conditionals, which means they get backed in when you build. I believe that you use something like below for runtime conditionals.

if #available( macOS 11.0, * ) { }

Edit 2: To include this potential sample.

if ProcessInfo.processInfo.isMacCatalystApp || ProcessInfo.processInfo.isiOSAppOnMac {}


Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.