I have added an iOS 15+
function to my app and now it is crashing on my M1 iMac running in iPad Mac Catalyst mode on macOS 11.6. Could this be a potential bug in macOS, Xcode or Swift?
I have this code:
if #available(iOS 15.0, macCatalyst 15.0, *) {
dataSource.applySnapshotUsingReloadData(fullSnapshot, completion: nil)
} else {
dataSource.apply(fullSnapshot, animatingDifferences: false)
}
When I run it on my mac, I can see it is running thinking it is iOS 14.7
using print(UIDevice.current.systemVersion)
however it runs the code within the available
check and crashes because it is not available on my macOS version yet!
I have tried using this code too:
#if targetEnvironment(macCatalyst)
print("HERE")
#else
print("HERE2")
#endif
and it prints HERE2 in the console!
I don't see how this is possible?
There is a known issue with Swift's availability checks specifically for iOS apps running on Apple silicon. Here is the information in the Xcode 13 Release Notes about it:
Availability checks in iPhone and iPad apps on a Mac with Apple silicon always return true. This causes iOS apps running in macOS 11 Big Sur to see iOS 15 APIs as available, resulting in crashes. This only affects apps available in the Mac App Store built with the “My Mac (Designed for iPhone)” or “My Mac (Designed for iPad)” run destination. It doesn’t affect Mac Catalyst apps. (83378814)
Workaround: Use the following code to check for iOS 15 availability:
if #available(iOS 15, *), ProcessInfo.processInfo.operatingSystemVersion.majorVersion >= 15 {