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

#endif

 
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

#endif

 
Hope it helps,

 
Thanks & Regards
Mandar Apte

Mandar Apte

This website contains a design articles blog by Mandar Apte. He writes and shares his iOS development, graphic, web, & animation film design experience through articles. Mandar is Mumbai based multi-disciplinary designer with expertise in UI, UX, Logo, Symbol, and Brand Identity design. He is an alumnus of Sir J. J. Institute of Applied Art, Mumbai. He currently runs his studio in the heart of the city of Mumbai.

Leave a Reply

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