[英]Trying to use Objective C cocoa pod in Swift project, bridging file compiled as Swift code
I'm trying to use an objective C based cocoa pod (GCM) in a Swift based iOS project.我正在尝试在基于 Swift 的 iOS 项目中使用基于客观 C 的可可豆荚 (GCM)。 I have the cocoa pods installed and I've created a bridging file by hand, adding it to the build preferences as a bridging file.
我安装了可可豆荚,并手动创建了一个桥接文件,将其作为桥接文件添加到构建首选项中。 The problem is that when I compile, the bridge.h file is compiled as Swift (when obviously it should be objective C).
问题是当我编译时,bridge.h 文件被编译为 Swift(显然它应该是目标 C)。 More explicitly- all of the lines inside the included.h files are throwing errors, not the bridg file itself.
更明确地说-included.h 文件中的所有行都在抛出错误,而不是桥接文件本身。 Here's my bridge file
这是我的桥文件
#ifndef bridge_h
#define bridge_h
#import <GoogleCloudMessaging.h>
#endif /* bridge_h */
Any idea what is going wrong and why the code being imported isn't treated as Objective C?知道出了什么问题以及为什么导入的代码不被视为目标 C 吗?
With the help of a coworker we figured it out- the bridging file must include Foundation/Foundation.h and must do so before it includes anything else.在同事的帮助下,我们弄清楚了 - 桥接文件必须包含 Foundation/Foundation.h,并且必须在包含其他任何内容之前这样做。 Otherwise it fails to compile.
否则编译不通过。
You have the possibility to check and change your file type in the file inspector when you have your file selected.选择文件后,您可以在文件检查器中检查和更改文件类型。 Look if it's objective-c header.
看看它是否是objective-c 标头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.