将Swift类导入Objective c [英] Import Swift class into Objective c

查看:93
本文介绍了将Swift类导入Objective c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的Object-c项目中使用Swift类.到目前为止,我已经创建了Objective-C项目并导入了swift类,并且它询问我是否要配置Objective-C桥接头?然后单击创建桥接头",从而创建了productname-Bridging-Header.h文件. .

I'm trying to use the Swift class in my Object-c project. So far I have created the Objective-C project and imported the swift class and it asked me Would you like to configure an Objective-C bridging header?, then I hit Create Bridging Header so the productname-Bridging-Header.h file is created.

然后我改变了

Always Search User Paths-->YES
SWIFT_OBJC_BRIDGING_HEADER-->YES

之后,我将swift类导入到我的viewController.m类

After that I import the swift class into my viewController.m class

示例:#import"Swiftclass.swift.h"

Example: #import "Swiftclass.swift.h"

但是它说#import"Swiftclass.swift.h"文件未找到

But it says #import "Swiftclass.swift.h" file not found

推荐答案

您需要导入ProjectName-Swift.h.

如果您的项目名称包含空格,请用下划线替换(例如,我的项目"变为"My_Project-Swift.h")

If your project name contain spaces, replace them with underscores (e.g. "My Project" becomes "My_Project-Swift.h")

就像

 #import "My_Project-Swift.h"

尝试这样.它会为您提供帮助.

Try like this. it will help you.

这篇关于将Swift类导入Objective c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆