How conditional code for and identify device between iOS (iPhone), iPadOS (iPad) & macOS Catalyst (Apple Macintosh)

If you are developing macOS catalyst app then you may be wondering how to conditionally write code specifically for iOS and iPad OS or macOS 10.15 catalyst app.

Here is how to do it.

Use below code to declare code specifically written and that will compile only for iOS and iPadOS.


#if !targetEnvironment(macCatalyst)
// Code that will execute only on iOS 13, iPadOS 13 and above


Use below code to specifically compile only for macOS 10.15 Catalina Catalyst app and above.


#if targetEnvironment(macCatalyst)
// Code that will execute only on Mac


Hope it helps,

Thanks & Regards
Mandar Apte

Leave a Reply

Your email address will not be published. Required fields are marked *