我当前的项目包含 Swift 和 Objective-C 代码。两种类型的源文件都使用另一种语言的代码。
当我进行完全清理并重新编译时,几乎每个 Swift 类声明都出现错误Module-Swift.h
,形式为:
Cannot find interface declaration for 'UIViewController', superclass of 'CustomViewController'
我的症状类似于这个问题 https://stackoverflow.com/questions/29285930/swift-objective-c-project-generated-swift-h-error-cannot-find-interface-d,在类似的情况下这个问题 https://stackoverflow.com/questions/25670431/how-to-prevent-circular-reference-when-swift-bridging-header-imports-a-file-that。换句话说:
-
Module-Bridging_Header.h
导入我的 Objective-C 头文件,Class.h
- 实施文件
Class.m
导入 Swift 标头,Module-Swift.h
如果我遵循答案中的方法这个问题 https://stackoverflow.com/questions/24098408/how-can-i-add-forward-class-references-used-in-the-swift-h-header,我可以通过添加以下文件并导入该文件来解决该错误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 中实现此目的的正确方法?
在 Obj-C 文件中,您需要导入 swift 模块(使用#import "Module-Swift.h"
).
仅在要使用 Swift 模块中定义的类型的文件中执行此操作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)