1

我正在尝试在 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 发送事件?

4

1 回答 1

1

您需要将其覆盖为 var getter:

  @objc
  override var methodQueue: DispatchQueue {
    get {
      return DispatchQueue.main
    }
  }

于 2020-10-16T10:33:09.273 回答