Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conditional if on import for objective c

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.
}
like image 503
user2679041 Avatar asked Oct 31 '25 07:10

user2679041


1 Answers

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.

like image 129
skaak Avatar answered Nov 01 '25 22:11

skaak