我正在尝试在 Swift 中创建一个需要在主线程上运行并将事件发送到 JS 的 React Native 本机模块。这很好用(如RN docs中所述):
@objc(MyModule)
class MyModule: NSObject {
@objc
func methodQueue() -> DispatchQueue {
return DispatchQueue.main
}
}
发送事件的推荐方法RCTEventEmitter
是扩展. 当我在上面的代码中更改NSObject
为时RCTEventEmitter
,我收到错误:
Method 'methodQueue()' with Objective-C selector 'methodQueue' conflicts with getter for 'methodQueue' from superclass 'RCTEventEmitter' with the same Objective-C selector
如何methodQueue
在扩展的同时覆盖吸气剂RCTEventEmitter
?还是有其他方法可以向 JS 发送事件?