在自动生成的Swift桥接头中找不到"接口声明"

sap*_*api 10 xcode objective-c swift

我当前的项目包含Swift和Objective-C代码.两种类型的源文件都使用其他语言的代码.当我完全清理并重新编译时,几乎每个Swift类声明都会Module-Swift.h出现以下形式的错误:

Cannot find interface declaration for 'UIViewController', superclass of 'CustomViewController'
Run Code Online (Sandbox Code Playgroud)

这个问题的类似情况下,我的症状类似于这个问题.换一种说法:

  • Module-Bridging_Header.h 导入我的Objective-C标头, Class.h
  • 实现文件Class.m导入Swift头,Module-Swift.h

如果我按照ansewrs中的方法来解决这个问题,我可以通过添加以下文件来解决错误,并将其导入以代替Module-Swift.h:

//
//  Module-Swift-Fixed.h
//  Module
//

#ifndef Module_Swift_Fixed_h
#define Module_Swift_Fixed_h

#import <Foundation/Foundation.h>

#import <CoreData/CoreData.h>
#import <UIKit/UIKit.h>

#import "Module-Swift.h"

#endif /* Module_Swift_Fixed_h */
Run Code Online (Sandbox Code Playgroud)

这看起来像是一个可怕的黑客.我错过了在Xcode中实现这一目标的一些方法吗?

Ene*_*nso 1

在 Obj-C 文件中,您需要导入 swift 模块(使用#import "Module-Swift.h")。

仅在要使用 Swift 模块中定义的类型的文件中执行此操作。