[Xcode] Warn about new API Classes and Methods

What?

Your project minimum iOS version is 5.0.
You are using SDK 6.1 and want to know if some method or some classes used in project are unavailable for iOS < 6.1?

Since Xcode don’t warn about it… here a trick to warn by yourself!


Headers

Files you need to read/know before continue:

[iOSSimulatorSDK] usr/include/Availability.h
[iOSSimulatorSDK] usr/include/AvailabilityInternal.h

Located in “/Applications/Xcode.app/Contents/Developer/Platforms/
iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/usr/include


Error or Warning?

You can also customize __attribute__ warning/error:

__attribute__((deprecated("UNAVAILABLE PRIOR TO 6.0")))

__attribute__((unavailable("UNAVAILABLE PRIOR TO 6.0")))

In your code:

Ok, give me the code!

In your prefix.pch, add on top these lines:

[code lang=”csharp” autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”]#import &lt;availability .h&gt;
#import &lt;foundation /NSObjCRuntime.h&gt;#if( 1 )

#define APICHECK_2_0( _ios ) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_##_ios)
#define APICHECK_2_1( _ios ) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_##_ios)
#define APICHECK_2_2( _ios ) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_##_ios)
#define APICHECK_3_0( _ios ) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_##_ios)
#define APICHECK_3_1( _ios ) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_##_ios)
#define APICHECK_3_2( _ios ) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_##_ios)
#define APICHECK_4_0( _ios ) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_##_ios)
#define APICHECK_4_1( _ios ) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_##_ios)
#define APICHECK_4_2( _ios ) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_##_ios)
#define APICHECK_4_3( _ios ) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_##_ios)
#define APICHECK_5_0( _ios ) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_##_ios)
#define APICHECK_5_1( _ios ) __attribute__((deprecated("UNAVAILABLE PRIOR TO 5.1")))
#define APICHECK_6_0( _ios ) __attribute__((deprecated("UNAVAILABLE PRIOR TO 6.0")))
#define APICHECK_6_1( _ios ) __attribute__((deprecated("UNAVAILABLE PRIOR TO 6.1")))
#define APICHECK_NA( _ios )  __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_##_ios)

#undef NS_AVAILABLE_IOS
#define NS_AVAILABLE_IOS(_ios) APICHECK_ ## _ios( _ios )

#undef NS_AVAILABLE
#define NS_AVAILABLE(_mac, _ios) APICHECK_ ## _ios( _ios )

#endif[/code]

NOTE:
Remove this code before submit to store. I don’t know what happens if you change system define!

have fun.

Ref:
http://goo.gl/S1NZD
http://goo.gl/Yxblh
albertopasca.it

 

Alberto Pasca

Software engineer @ Pirelli & C. S.p.A. with a strong passion for mobile  development, security, and connected things.