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
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
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