Is there a way for Xcode to warn about new API calls? Is there a way for Xcode to warn about new API calls? ios ios

Is there a way for Xcode to warn about new API calls?


I've actually released something which helps with testing this sort of thing. It's part of my MJGFoundation set of class called MJGAvailability.h.

The way I've been using it is to apply it in my PCH file like this:

#define __IPHONE_OS_VERSION_SOFT_MAX_REQUIRED __IPHONE_4_0#import "MJGAvailability.h"// The rest of your prefix header as normal#import <UIKit/UIKit.h>

Then it'll warn (with perhaps a strange deprecation warning) about APIs which are being used that are too new for the target you set as the "soft max" as per the #define __IPHONE_OS_VERSION_SOFT_MAX_REQUIRED. Also if you don't define __IPHONE_OS_VERSION_SOFT_MAX_REQUIRED then it defaults to your deployment target.

I find it useful because I can then double check which APIs I'm using that are too new for the deployment target that I've set.


If you use XCode7.3 and above, you can set other warning flag: -Wpartial-availability, then xcode will show warning for API newer than deployment target versionenter image description here


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 supported

#define START_IGNORE_PARTIAL _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wpartial-availability\"")#define END_IGNORE_PARTIAL _Pragma("clang diagnostic pop")

I haven't test on iOS though.


matomo