I would like to use conditional if on import for objective c, didn't see any API for this and wanted to know if this is possible. (this is for adding an import only for a specific IOS) so far I saw this check but it's only for the code, not at the import stage Thanks
if (@available(iOS 11, *)) {
// Use iOS 11 APIs.
} else {
// Alternative code for earlier versions of iOS.
}
You could use one of the foundation framework version numbers, like so.
#ifdef NSFoundationVersionNumber_iOS_8_0
#import "this.h"
#else
#import "that.h"
#endif
or even
#if NSFoundationVersionNumber > 10
#import "this.h"
#else
#import "that.h"
#endif
This is a bit different to the @available that you mention, which checks at runtime. This will check on compile time and depend on your target iOS and it seems it is no longer kept up to date, but worth a try if your requirement is compile time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With