在objective-c中导入swift类,找不到< myModule> -Swift.h文件 [英] import swift class in objective-c, <myModule>-Swift.h file not found
问题描述
我有一个用Objective-C编写的iOS项目。我在项目中创建了一个Swift类,成功生成了用于访问Swift中的objective-c的桥接头文件,它工作正常。
I have an iOS project written with Objective-C. I created an Swift class in the project, the bridging header file for accessing objective-c in Swift is generated successfully, and it works fine.
我的问题是另一种方式。我想在Objective-c代码中导入Swift类。
My problem is the other way around. I want to import Swift class in objective-c code.
在xcode中, target - > Build Settings - > Swift Compiler 部分,I请参阅 Objective-C生成的接口标题名称
字段,其值为 myModule-Swift.h
,但是当我导入此标头时我的 objective-c 类:
In xcode, target -> Build Settings--> Swift Compiler section, I see Objective-C Generated Interface Header Name
field with value myModule-Swift.h
, but when I import this header in my objective-c class:
#import "myModule-Swift.h"
我收到编译错误:
myModule-Swift.h file not found
在项目中,我找不到此文件无论是。我该如何解决这个问题?
and in project, I cannot find this file either. How can I solve this problem?
我的xcode版本是6.4
My xcode version is 6.4
推荐答案
< h2> 2018年5月更新Xcode 9.3
Updated May 2018 Xcode 9.3
- 构建设置 - > Objective-C生成的接口标题命名
并将值设置为YourModule-Swift.h(这通常已设置,这是您需要在 .m 文件#import上导入的文件名YourModule -Swift.h
- Build Settings->Objective-C Generated Interface Header Name
and set the value to YourModule-Swift.h (this is usually already set, this is the filename you need to import on .m file#import "YourModule-Swift.h"
(示例,项目名为 CData
)
-
与步骤1相同,转到构建设置并搜索定义模块,将两个值都设置为YES
Same as Step 1, Go to Build Settings and search for "Defines Module", set both values to YES
创建一个扩展 NSObject
的类 .swift
file
Create a class that extends NSObject
on .swift
file
-
再次构建项目
Build the project again
导入 YourModule-Swift.h
.m 文件中的文件(请注意它区分大小写, Mymodule
!== MyModule
)
Import YourModule-Swift.h
file on .m file (Please notice it's case sensitive, Mymodule
!== MyModule
)
这篇关于在objective-c中导入swift类,找不到< myModule> -Swift.h文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!