ios 禁用模块时使用@import

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29701647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 05:40:26  来源:igfitidea点击:

use of @import when modules are disabled

iosxcodeimportmodule

提问by ali rezaei

I have a problem

我有个问题

@import Foundation;

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

我看到:
@import vs #import - iOS 7

and I set "Enable Modules" to "YES"

我将“启用模块”设置为“是”

and my problem is not solved

我的问题没有解决

回答by Peter Brockmann

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

每当我尝试添加@import SafariServices;语句时,我都会在零快速项目中收到此警告。

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

解决方案: 启用模块。转到 Target > Build Settings 并将 Enable Modules(C 和 Objective-C 模块)设置为YES

I've circled the Build Settings toggle to change.

我已经圈出了要更改的构建设置切换。

回答by Aleks N.

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

可能的原因是您使用了 Objective-C++。然后,尽管构建设置正确,模块也会被禁用。

回答by Warren Stringer

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

我一直在混合 ObjC、ObjC++、C++ 和 Metal。每当我得到“禁用模块时使用@import”时,我都会尝试替换:

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

它似乎工作。

回答by Uday Sravan K

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

检查您是否正在使用#import "ProductName-Swift.h".mm 文件或 objc 文件以外的任何其他文件。

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

因为如果您在 cpp 文件中使用此导入,则会自动禁用模块。