0

If I use a feature which is deprecated at current SDK version, compiler will warn about it. I'm finding a feature just opposite against it.

If I use a class or method which is not defined in specific SDK version, compiler warn about it.

How can I gain this feature? I tried defining __IPHONE_OS_VERSION_MAX_ALLOWED by putting definition on prefix-header like this,

#undef      __IPHONE_OS_VERSION_MAX_ALLOWED
#define     __IPHONE_OS_VERSION_MAX_ALLOWED         40000

but it catches any of version mismatch even in SDK itself. (such as UIKit)

I'm making library code needs backward compatibility for iOS 4.0, and I want some automated method to check backward compatibility. I know feature availability test won't solve everything, but this will make the work a lot easier.

How can I check feature availability for specific SDK version with compiler?

eonil
  • 83,476
  • 81
  • 317
  • 516

2 Answers2

0

This sounds like a job for respondsToSelector, where you can check to see if a selector exists in the OS you are currently running on.

But if you really want to future-proof your app, you should always go for the newest API defined for the minimum OS version you want to support.

Here is a related question about 'respondsToSelector' that may help you out.

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • I'm sorry for unclear question, but what I need was automated backward compatibility test at compile time. Thanks anyway. – eonil Apr 19 '12 at 07:05
0

I think what you need is to check for a class (feature) before attemp to use it by using the NSClassFromString.

Class myClass = NSClassFromString(@"CLassThatYouWantToUse"); //get the class object
if (myClass != nil)
    {
       // The device will support this class.. so carry on...
     }
else
      {
           // The device doesn't support this class.
       }
user523234
  • 14,323
  • 10
  • 62
  • 102