自动生成的 Swift 桥接头中的“找不到接口声明" [英] 'Cannot find interface declaration' in auto-generated Swift bridging header
问题描述
我当前的项目包含 Swift 和 Objective-C 代码.两种类型的源文件都使用另一种语言的代码.当我完全清理并重新编译时,我在 Module-Swift.h
中的几乎每个 Swift 类声明中都会出现错误,形式如下:
My current project contains both Swift and Objective-C code. Both types of source file use code from the other language.
When I do a full clean and recompile, I get errors on almost every single Swift class declaration in Module-Swift.h
, of the form:
Cannot find interface declaration for 'UIViewController', superclass of 'CustomViewController'
My symptoms are similar to this question, in similar circumstances to this question. In other words:
Module-Bridging_Header.h
导入我的 Objective-C 头文件,Class.h
- 实现文件
Class.m
导入 Swift 头文件,Module-Swift.h
Module-Bridging_Header.h
imports my Objective-C header,Class.h
- The implementation file
Class.m
imports the Swift header,Module-Swift.h
如果我按照答案中的方法 这个问题,我可以通过添加以下文件来解决错误,并导入它代替 Module-Swift.h
:
If I follow the approach in the ansewrs to this question, I can resolve the error by adding the following file, and importing that in place of 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 */
这似乎是一个可怕的黑客攻击.我是否缺少在 Xcode 中实现此目标的正确方法?
This seems like a horrible hack. Am I missing some proper way to achieve this in Xcode?
推荐答案
在 Obj-C 文件中,您需要导入 swift 模块(使用 #import "Module-Swift.h"
).
In Obj-C files, you need to import the swift module (with #import "Module-Swift.h"
).
仅在要使用 Swift 模块中定义的类型的文件中执行此操作.
Do this only in the files where you are going to use types defined in your Swift module.
这篇关于自动生成的 Swift 桥接头中的“找不到接口声明"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!