Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if modules are supported in Xcode?

When I enable the -Weverything custom compiler flag and modules are supported in Xcode, it tells me to switch to using modules - so I change this type of thing:

#import <Foundation/Foundation.h>

to this:

@import Foundation;

...and everything is fine until someone later imports one of my classes into their legacy projects that do not have modules enabled, at which point they have to revert the @import to a #import.

My question is this: Is it possible to wrap these in some sort of preprocessor macro to pick out the correct one at compile time?

Example of what I'm hoping for:

#ifdef MODULES_SUPPORTED
    @import Foundation;
#else
    #import <Foundation/Foundation.h>
#endif

Thanks

Jase

like image 391
Jason Coulls Avatar asked Oct 31 '14 16:10

Jason Coulls


1 Answers

This is an old question, but needed to know how to do this too. Here is a way to do it:

#ifdef __has_feature(modules)
    @import Foundation;
#else
    #import <Foundation/Foundation.h>
#endif

Reference: CLANG LANGUAGE EXTENSIONS

like image 65
zim Avatar answered Sep 28 '22 07:09

zim