无法导入桥接头 [英] Failed to import bridging header
问题描述
我已经阅读了许多涉及类似问题的问题和答案,但我还没有找到解决方案。如果有人能说清楚,那就太棒了。
I've read a lot of questions and answers that deal with a similar issue, but I have yet to find a solution. If anyone could shed some light, that would be wonderful.
我创建了一个Swift项目,现在我想将它与一些Objective-C结合起来。当我尝试#import我的Chartboost.h文件时,我的无法导入桥接头。所以,只要我的桥接头文件中没有任何内容,Xcode就会找到并且没有任何问题。但是,一旦我添加了这个:
I created a Swift project and now I want to combine it with some Objective-C. My "failed to import bridging header" only occurs when I attempt to #import my Chartboost.h file. So, as long as I don't have anything in my bridging header file, Xcode finds it and gives me no issue. But once I add this:
#import <Chartboost/Chartboost.h>
我得到错误以及其他38个错误,说Swift编译错误 - 此处不允许函数定义 。
I get the error along with 38 other errors saying "Swift Compiler Error - Function definition not allowed here".
我已经正确导入了我的框架。我的框架搜索路径是正确的。而且只有在我导入Chartboost框架时才会这样。 UIKit和基金会工作正常。
I've correctly imported my framework. And my framework search path is correct. And it's only when I import the Chartboost framework. UIKit and Foundation work fine.
这就是我在这个问题上所做的工作....首先,我创建了一个新的Obj-C文件然后点击是当Xcode给我一个弹出窗口,询问它是否可以配置桥接头。这创建了FunFacts-Bridging-Header.h
Here is what I did leading up to the issue....First, I created a new Obj-C file and then clicked "Yes when Xcode gave me a pop-up asking if it could configure a bridging header. This created "FunFacts-Bridging-Header.h"
然后我确定了Objective-C在Swift编译器 - 代码生成下,桥接头路径是正确的。
Then I made sure Objective-C Bridging Header path was correct under Swift Compiler - Code Generation.
我甚至放入了一个非常具体的路径/ Users / me / Desktop / FunFacts / FunFacts-Bridging-Header。 h
,它仍然说导入失败。
I even put in a very specific path /Users/me/Desktop/FunFacts/FunFacts-Bridging-Header.h and it still says "Failed to import".
我还将定义模块设置为是(因为我听说这可能有帮助)。我的产品模块名称是FunFacts。
I've also set Defines Module to "Yes" (because I heard that may help). And my product module name is FunFacts.
当我尝试添加#import时,为什么FunFacts-Bridging-Header.h无法导入?
Why is FunFacts-Bridging-Header.h failing to import when I try to add #import ?
推荐答案
我想出了2个解决方案!
I figured out 2 solutions!
1)这不是最漂亮的方法它,但我将我的Chartboost.h文件中的所有代码复制并粘贴到我的Bridging-Header.h中文件而不是导入。这很有效。但我知道有更好的方法,所以我一直在寻找......
1) This isn't the prettiest way to do it, but I copy and pasted all my code from my Chartboost.h file into my Bridging-Header.h file instead of importing . This worked. But I knew there was a better way, so I kept hunting...
2)我相信正确的解决方案是我接下来要做的。我的项目(不是目标)框架搜索路径是空的。所以,我继续添加了Chartboost SDK的路径,如下所示:/ Users / me / Desktop / Apps / SDKs / Chartboost
现在它构建并运行没有问题,我没有必要将所有内容复制并粘贴到桥接标头中。所需要的只是
2) The correct solution, I believe, is what I did next. My project's (not target) Framework Search Paths was empty. So, I went ahead and added the path to the Chartboost SDK like so: /Users/me/Desktop/Apps/SDKs/Chartboost
Now it builds and runs with no problem and I didn't have to copy and paste everything into the bridging header. All that was needed was
#import <Chartboost/Chartboost.h>
如果有人遇到类似问题,请阅读我在问题中所做的事情,然后按照得到这个答案。
If anyone is having a similar issue, just read what I did in my question, and then follow it up with this answer.
这篇关于无法导入桥接头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!