在我的react原生项目中,我尝试向javascript代码公开一个swift函数。 它在调试模式下运行良好,但在尝试存档时,我在swift文件上遇到了使用未声明类型RCTEventemitter
错误。
RCTEventemitter
导入到我的rnutils.m
文件和桥接头中。
所以我猜在归档的某个地方,桥接报头出现了故障,但我不知道在哪里。 如果我要求一个不存在的导入,它会告诉我它无法编译桥接头,因此在构建过程中会考虑该文件。
// Utils.m
#import "React/RCTBridgeModule.h"
#import "React/RCTConvert.h"
#import "React/RCTEventEmitter.h"
@interface RCT_EXTERN_REMAP_MODULE(RNUtils, RNUtils, RCTEventEmitter)
@end
// Utils.swift
import Foundation
@objc(RNUtils)
class RNUtils: RCTEventEmitter {
// my native code emitting events
}
// MyApp-Bridging-header.h
#ifndef MyApp_Bridging_Header_h
#define MyApp_Bridging_Header_h
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
#endif
似乎我需要在每个swift文件中添加“§mport react”。 现在存档很好。