Swift“Bridging-Header.h”文件不允许我在.swift文件中实例化objective-c类 [英] Swift "Bridging-Header.h" file not allowing me to instantiate objective-c classes in .swift files

查看:221
本文介绍了Swift“Bridging-Header.h”文件不允许我在.swift文件中实例化objective-c类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当X代码尝试自动创建桥接头时,它每次都会崩溃,因此我按照有关如何手动创建桥接头的说明进行操作。
(创建.h文件,将其命名为< #PROJECT_NAME> -Bridging-Header.h,导入所需的所有.h文件?)

When X-code tries to create a bridging header automatically, it crashes every single time, so I followed the instructions on how to manually create a bridging header. (Create a .h file, name it <#PROJECT_NAME>-Bridging-Header.h, import all the .h files you need?)

问题是,当我尝试在包含在该头文件中的.swift文件中实例化一个类时,没有任何反应(它表示该类不存在)另外,在桥接头中,它似乎不会自动完成我的文件名试着把它们包括在内,让我相信一些没有正确联系的东西。

Problem is, when I try to instantiate a class in the .swift file that's included in that header, nothing happens (it says that class doesn't exist) Also, in the Bridging Header it doesn't seem to autocomplete my filenames when I try to include them, leading me to believe somethings not linking properly.

有没有人碰到这个?有谁知道如何修复它?

Has anyone run into this? Does anyone know how to fix it?

推荐答案

您需要将其添加到目标的构建设置中:

You need to add it to your target's build settings:


  1. 在Xcode中,如果你进入目标的构建设置,并一直向下滚动,你会找到一个Swift编译器 - 代码生成 部分。

  1. In Xcode, if you go into the build settings for your target, and scroll all the way down you'll find a "Swift Compiler - Code Generation" section.

将Objective-C Bridging Header设置为< #PROJECT_NAME> -Bridging-Header.h

Set "Objective-C Bridging Header" to <#PROJECT_NAME>-Bridging-Header.h

我不确定安装Objective-C兼容性标题的正确值,但它是肯定/否,因此您可以切换如果它最初不起作用。

I'm not sure of the correct value for "Install Objective-C Compatibility Header", but it's a yes/no, so you can toggle that if it doesn't work at first.

这篇关于Swift“Bridging-Header.h”文件不允许我在.swift文件中实例化objective-c类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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