简体   繁体   中英

Objective-c class exposed via bridging header not visible from swift when archiving release

In my react native project, I try to expose a swift function to the javascript code. It works well in debug mode, but when trying to archiving I get a Use of undeclared type RCTEventEmitter error on my swift file.

The RCTEventEmitter is imported in my RNUtils.m file, and in the bridging header.

So I guess somewhere in the archiving, something fail with the bridging header, but I have no idea where. If I ask for a non existing import, it will tell me that it can't compile the bridging header, so the file is taken into account during the build.

// 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
  • react-native 0.61.5
  • xcode 11.5
  • Swift 5

It appears I needed to add ìmport React` in every swift file. It's archiving fine now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM