10

I have a project that uses CocoaPods and uses the 'SCLAlertView-Objective-C' pod. That pod uses the @import UIKit; module style import. I've set "Enable Modules (C & Objective-C)" and the "Link Frameworks Automatically" to YES in both my target and project settings. I am still getting the "Use of '@import' when modules are disabled" error.

Is there anything that could prevent Xcode from being able to enable Modules such as the use of a .pch file, any linker flags, or anything else I haven't mentioned? I also tried to clean the project and the project build folder. That didn't have any effect.

Also worth noting is that my project has multiple targets and also has a deployment target of iOS 7.0. My Base SDK is set to iOS 8.3.

Screenshot of target build settings for modules

1
  • Have you found a solution? I have the same problem with Google Analytics. Thanks in advance! Commented Jul 17, 2015 at 11:38

3 Answers 3

8

I guess your project contains XXX.mm files, however, the xcode only enable C and objective-c modules.

Please have a look at this answer for your reference: Using @import in objective C in conjunction with __cplusplus

my solution is modify the @import xxx into #import .

Good luck.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, only #import works. Could not get modules working due to the same error described here. #import <Firebase/Firebase.h> works
6

I just solved this in a primarily ObjC++ project I was working on that needed to use Firebase.

Simply make a ObjC (.m) file which contains the following.

#import <Foundation/Foundation.h>
@import Firebase; // << swap this for your specific import

That's it, then simply use #include in your .mm files for the specific headers you need. For me that meant:

#include <"Firebase/Firebase.h">
#include <"FirebaseAuth/FirebaseAuth.h">

Just to stress the point, no amount of fiddling with link options made any difference to this "Enable Modules (C & Objective-C)" was already YES. Upgrading to XCode7 didn't seem to help.

Hope this helps someone :)

1 Comment

I've done this. Same error in the newly added .m Objective-C file. I have no .mm files. Checked everything outlined in this thread. Still same error. Xcode 8.3
3

The build option does not really work as it should. I've solved this problem by adding -fcxx-modules (Objective C++) or -fmodules (Objective C) manually to "C Flags"/"C++ Flags".

Worked for me.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.