warning if method availability is newer than minimum deployment target


i am trying to generate warnings building an xcode project when calling a method that is available later than the current minimum deployment target. is this a job for a clang analyzer plugin, or is there some easier way to achieve this that i am not aware of?


In theory it's really straightforward to do; there's an availability attribute which should give us this information. In practice it's quite a bit harder because real code often intentionally uses APIs that aren't available on the minimum deployment target, and that's totally fine *if that code just doesn't run on such targets*. Detecting that latter condition and suppressing the warning there is quite a bit harder.


Hi Richard,

John is absolutely right. There are well-known idioms, such as those published in Apple’s SDK Compatibility Guide, which allow to use APIs newer than your minimum deployment target but then gracefully degrade when not running on a newer OS. Doing this well regards doing dataflow and control-flow analysis. It’s something I have been thinking about recently, and if you have specific concerns or requests about such a warning I would love to hear them.


hey ted, john

i understand the concept of weak linking to apis newer than the deployment target, but it is very easy to accidentally include api calls and receive no warning about this until the app crashes at runtime, and it is not really feasible to test an entire app flow on all possible ios versions when updating older projects. i have recently had to fix a couple of bugs for this exact reason.

perhaps it would be nice just to have an optional analysis step that would always output a warning to highlight api calls that are newer than the minimum deployment target, that could be ignored by the developer if an optional code path has been used? i feel that accidentally including newer apis is probably the more common case than the developer correctly handling this situation (well it is where i work anyway :). i agree that doing this right is a lot more work, and unless a standard convention is used it is going to be almost impossible to do well.


Hi Richard,

I think it would be easy to add a warning that checks if a use API is newer than the minimum deployment target, but I would not want that warning to go into mainline Clang because (1) most developers would hate the warning as it would produce too many false positives and (2) I believe we can do much better than that. While it might be “hard” to get it right, I think it is quite doable.

I’m curious about your last comment, that “unless a standard convention is used it is going to be almost impossible to do well.” Can you elaborate? I thought there were standard conventions for checking for weak linked APIs, etc?


hey ted,

perhaps you are right, maybe i was just being too lazy. the current documentation on using weakly linked apis is here:


so maybe it is as simple as checking that every call to an api newer than the minimum deployment target is contained in a block like this example:

if ([UIImagePickerController instancesRespondToSelector:@selector (availableCaptureModesForCameraDevice:)]) {
// Method is available for use.
} else {
// Method is not available.

but i have the feeling there are some edge cases to take care of here, as well as handling C apis.