Essentially what the subject says. I'm getting conflicting information from AI tools on this subject.
1 Answer 1
And to answer my own question, after experimenting with both I realized that there is in fact a huge difference between the two:
#if IOS will target only iOS devices (iPhones)
#if __IOS__ on the other hand will target iOS and MacCatalyst (and possibly other stuff like TvOS, WatchOS, ...)
I find the __IOS__ approach very misleading and dangerous for my taste and here's why. We had a piece of code that was like this:
#if __IOS__
// do stuff
#end
We then wanted to add special handling for other apple stuff like MacCatalyst. So we tried:
#if __IOS__ // this matches both iOS and MacCatalyst!
// do stuff
#elif MACCATALYST // wops! this will not be honored because the first #if above already matched MACCATALYST!!
// do stuff for MacCatalyst
#end
Going forward I will be siding with the explicit approach to avoid such pitfalls
#if IOS // now I know this will only match iOS and nothing else
// do stuff
#elif MACCATALYST
// this will now work
#endif
Hope this helps folks out there save a few hours worth of headaches.
Comments
Explore related questions
See similar questions with these tags.