ios - 不能使用自动生成的 Swift 桥接头

标签 ios objective-c swift bridging-header

我试图在 Objective-C 类中使用自动生成的 Swift 桥接 header ,但是当我尝试包含它时,我在桥接 header 中遇到了很多错误。由于 header 是自动生成的,所以根本不清楚我可能有什么错误。

在 Objective-C 类中,如果我声明以下行,我将遇到构建错误 - 没有此行,没有错误并且构建正常:

#import "Oilist-Swift.h"

编辑:我刚刚移动了 #import "Oilist-Swift.h"在导入所有其他 header 后声明,现在我只收到与 MFMailComposeViewControllerDelegate 相关的错误并且可能有一个与 PopupStoreControllerDelegate 相关的错误.以下是现在所有的错误:

Angle brackets contain both a protocol ('PopupStoreControllerDelegate') and a type ('MFMailComposeViewControllerDelegate')

Unknown class name 'MFMailComposeViewControllerDelegate'; did you mean 'MFMailComposeViewController'?
Replace 'MFMailComposeViewControllerDelegate' with 'MFMailComposeViewController'

- (void)mailComposeController:(MFMailComposeViewController * _Nonnull)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError * _Nullable)error;
  Expected a type (MFMailComposeResult)

我一直在寻找循环引用,但到目前为止找不到。

如有任何见解,我们将不胜感激!

现在看起来真的很接近了 - 它似乎只是出于某种未知原因对 MFMail 不满意。

最佳答案

如果我导入 MessageUI.h,它现在可以工作了。 (尽管在导入 Swift header 的类中根本没有使用 MessageUI)。

我想我必须导入 MessageUI,因为它在桥接 header 中被引用并且不包含 MessageUI 内容的定义...

解决方法:

#import <MessageUI/MessageUI.h>
#import "Oilist-Swift.h"

关于ios - 不能使用自动生成的 Swift 桥接头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47044051/

相关文章:

ios - Realm 中如何处理逆?

ios - 使用 EventKit 添加事件和日历

objective-c - 使用数据加载自定义 ViewController

ios - 我怎样才能得到联系ID

objective-c - 是否可以使用 CGContext 绘制图形并将它们保存到 NSMutableArray 中?

objective-c - 通过 UIAlerView+AFNetworking 在 UIAlertView 中显示错误消息

ios - 在 iOS 中画一个方框

swift - 如何在扩展 SequenceType 的协议(protocol)中限制 Generator.Element 的类型

ios - 在 Swift 中使用 NSFileManager 删除文件时无法获得完成结果

ios - 在 IOS 上使用 Quartz 2d 以编程方式绘制线条动画