The answer to this question does not appear to work on xcode 4.5. To summarise it, is there a way for XCode to warn about classes, methods and procedures that are only available a later version than the deployment target?
Asked
Active
Viewed 1,376 times
2 Answers
18
There is a correct answer inside of the question that you linked too. With some experimentation, I came up with this (from mattjgalloway's answer):
#define __AVAILABILITY_TOO_NEW __attribute__((deprecated("TOO NEW!"))) __attribute__((weak_import))
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0
#undef __AVAILABILITY_INTERNAL__IPHONE_6_0
#define __AVAILABILITY_INTERNAL__IPHONE_6_0 __AVAILABILITY_TOO_NEW
#endif
Then repeat for all the versions that make sense (i.e. 4.3 and above for Xcode 4.5). The __IPHONE_OS_VERSION_MIN_REQUIRED
macro will check the deployment target.

borrrden
- 33,256
- 8
- 74
- 109
-
+1 for such a brilliantly filthy precompiler hack. Repeat the body of this for iOS 5 and iOS 6 warnings if you're an unfortunate sod who still has to support iOS 4. – Kiel Gillard Dec 10 '12 at 01:08
-
Very nice. It doesn't warn against everything, though. If I have Autolaypout turned on in my XIBs, there will be a runtime crash on an old SDK. – Jeff Jan 30 '13 at 20:53
-
Sadly, it does not warn for everything. I get a warning for `ABAddressBookCreateWithOptions` but not for `(NSString *)capitalizedStringWithLocale:(NSLocale *)locale` which are both new in iOS 6.0. – and3rs Feb 27 '13 at 09:16
-
Not working for me in Xcode 4.5.2; it doesn't warn about -application:willFinishLaunchingWithOptions: when deploying to iOS 5.1 (base SDK is "latest"). – randallmeadows Apr 17 '13 at 19:53
-
@randallmeadows Are you calling it directly, or just implementing it? – borrrden Apr 18 '13 at 01:20
-
@elpsk That method is marked just fine for me so you must have made an error setting it up. Trying putting it into the PCH file right after the `#import
` line. – borrrden Jun 27 '13 at 08:14 -
1This no longer works for me in Xcode 5 and iOS 7 -- anybody confirm? – Jeff Sep 13 '13 at 08:51
-
Well for one thing, you need to add a reference to the iOS 7 macro first. Other than that, I don't have that Xcode so I can't confirm. @Jeff – borrrden Sep 13 '13 at 08:52
-
Yup, I've changed all the "_6_0" to "_7_0". I think it has something to do with a compiler flag -- based on this comment in CFAvailability.h: "... compilers targeting iOS which support attribute_availability_with_message". But I'm really lost in all those macros. – Jeff Sep 15 '13 at 08:49
-
There are some new macros and changes in the way they are used that prevents this to work when using the iOS 7 SDK (and thus when using Xcode 5). – Rivera Oct 01 '13 at 08:40
-
Created a new question http://stackoverflow.com/questions/19111934/get-xcode-5-to-warn-about-new-api-calls – Rivera Oct 01 '13 at 08:56
0
This tool can do the job of finding too new API calls in your project: http://www.deploymateapp.com/

Holtwick
- 1,849
- 23
- 29