use of @import when modules are disabled

2019-02-07 16:38发布

I have a problem

@import Foundation;

and I see:
@import vs #import - iOS 7

and I set "Enable Modules" to "YES"

and my problem is not solved

4条回答
Anthone
2楼-- · 2019-02-07 17:21

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.

查看更多
beautiful°
3楼-- · 2019-02-07 17:26

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.

查看更多
甜甜的少女心
4楼-- · 2019-02-07 17:27

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.

查看更多
贼婆χ
5楼-- · 2019-02-07 17:42

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

查看更多
登录 后发表回答