[英]Swift “Bridging-Header.h” file not allowing me to instantiate objective-c classes in .swift files
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. 当X代码尝试自动创建桥接头时,它每次都会崩溃,因此我按照有关如何手动创建桥接头的说明进行操作。 (Create a .h file, name it <#PROJECT_NAME>-Bridging-Header.h, import all the .h files you need?)
(创建.h文件,将其命名为<#PROJECT_NAME> -Bridging-Header.h,导入所需的所有.h文件?)
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. 问题是,当我尝试在包含在该头文件中的.swift文件中实例化一个类时,没有任何反应(它表示该类不存在)此外,在桥接头中,它似乎没有自动完成我的文件名试着把它们包括在内,让我相信一些没有正确联系的事情。
Has anyone run into this? 有没有人碰到这个? Does anyone know how to fix it?
有谁知道如何修理它?
You need to add it to your target's build settings: 您需要将其添加到目标的构建设置:
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. 在Xcode中,如果你进入目标的构建设置,并一直向下滚动,你会发现一个“Swift编译器 - 代码生成”部分。
Set "Objective-C Bridging Header" to <#PROJECT_NAME>-Bridging-Header.h
将“Objective-C Bridging Header”设置为
<#PROJECT_NAME>-Bridging-Header.h
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. 我不确定“安装Objective-C兼容性标题”的正确值,但它是肯定/否定,所以如果它最初不起作用,您可以切换它。
I tried to create a bridging header myself but for some reason Xcode didn't like it. 我试图自己创建一个桥接头,但由于某种原因Xcode不喜欢它。 So i deleted my custom one, imported an Obj C file which made Xcode ask if I wanted it to create one for me.
所以我删除了我的自定义文件,导入了一个Obj C文件,该文件使Xcode询问我是否希望它为我创建一个。
I clicked yes, and it worked! 我点击了,它有效!
1) create a file called "FMDB-Bridging-Header.h" 1)创建一个名为“FMDB-Bridging-Header.h”的文件
inside this file type the following: #import "FMDB.h" 在此文件中键入以下内容:#import“FMDB.h”
3) go to Build Settings -> Swift Compiler - Code Generation - add to 'Objective-C Bridging Header': FMDB-Bridging-Header.h 3)转到Build Settings - > Swift Compiler - 代码生成 - 添加到'Objective-C Bridging Header':FMDB-Bridging-Header.h
or if it was placed inside a folder in your project: 或者如果它被放置在项目的文件夹中:
FolderName/FMDB-Bridging-Header.h 文件夹名称/ FMDB桥接,Header.h
Go to Build Settings > Build Options and set "Embedded Content Contains Swift Code" to "Yes" 转到Build Settings> Build Options并将“Embedded Content包含Swift Code”设置为“Yes”
Go to Build Settings > Linking and add "@executable_path/Frameworks" to Runpath Search Paths 转到Build Settings> Linking并将“@ executable_path / Frameworks”添加到Runpath搜索路径
Build your project now! 立即构建您的项目!
它可以帮助用它的Project根设置桥接头的名称,将“MyProject / MyProject-Bridging-Header.h”设置为Swift编译器构建密钥'Objective-C Bridging Header'的字符串值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.