use of @import when modules are disabled

IosXcodeImportModule

Ios Problem Overview


I have a problem

@import Foundation;

and I see:
https://stackoverflow.com/questions/18947516/import-vs-import-ios-7

and I set "Enable Modules" to "YES"

and my problem is not solved

Ios Solutions


Solution 1 - Ios

I got this warning in a zero-swift project whenever I tried to add the @import SafariServices; statement.

Solution: Enable the modules. Go to the Target > Build Settings and set the Enable Modules (C and Objective-C modules) to YES.

I've circled the Build Settings toggle to change.

OR

Note: I haven't verified this potential solution, but probably worthy of consideration if there are side effects caused by this solution.

> Rather than enabling modules to entire project, we can enable modules for a specific file which is importing c++ file. Go to build phases -> Compile Sources -> Select the file -> Add compiler flag -fmodules

Solution 2 - Ios

The possible cause is that you use Objective-C++. Then modules get disabled despite the proper build settings.

Solution 3 - Ios

I've been mixing ObjC, ObjC++, C++, and Metal. Whenever I get the "use of @import when modules are disabled" I try replacing:

@import Name; 

with:

#import "Name/Name.h"

example, replace:

@import Metal;
@import MetalKit;
@import CoreVideo;

with:

#import "Metal/Metal.h"
#import "MetalKit/MetalKit.h"
#import "CoreVideo/CoreVideo.h"

It seems to work.

Solution 4 - Ios

Check if you are using #import "ProductName-Swift.h" somewhere in .mm files or any other files other than objc files.

Because if you use this import in cpp files then modules gets disabled automatically.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAli RezaeiView Question on Stackoverflow
Solution 1 - IosPeter BrockmannView Answer on Stackoverflow
Solution 2 - IosAleks N.View Answer on Stackoverflow
Solution 3 - IosWarren StringerView Answer on Stackoverflow
Solution 4 - IosUday Sravan KView Answer on Stackoverflow