On more than one occasion I've seen crashing bugs appear on iOS 3.x due to use of a new call that was introduced in 4.x without proper checking.
Is there a way for XCode to warn about classes, methods and procedures that are only available a later version than the deployment target?
That way I could easily list through all the code and make sure it's properly conditionalized.
On OS X at least, with recent clang/SDK, there is now a
-Wpartial-availability
option (add it e.g. in "other warning options") One can then define the following macros to encapsulate code that handles runtime testing if the method is supportedI haven't test on iOS though.
After digging through
AvailabilityInternal.h
, I realized that all available versions above the Deployment target are tagged with the__AVAILABILITY_INTERNAL_WEAK_IMPORT
macro.Therefore, I can generate warnings by redefining that macro:
By placing this code in a project's precompiled header, any use of an API that might cause a crash on the lowest supported iOS version now generates a warning. If you correctly guard the call, you can disable the warning specifically for that call (modified exmaple from Apple's SDK Compatibility Guide):
No, there is no such warning. However, when you use new API (since you are obviously writing these later), just check the docs when they were available.
Also, if you're supporting 3.0 and using new SDK for development, you must absolutely be testing on actual devices running 3.0
Another thing you could do is write your own utility that parses the availability macros in the headers and then warns you if you're calling anything you shouldn't be.
However, I must reiterate, if you're targeting an older version and using the newer SDK, you must check the docs to see when API became available, and test appropriately.