How to bridge React Native Promise to Swift

后端 未结 3 1416
慢半拍i
慢半拍i 2021-02-12 14:46

Hi fellow software enthousiasts,

I am currently working on a React native project for which I need to add some logic which has been written in swift. I am able to trigge

3条回答
  •  心在旅途
    2021-02-12 15:03

    Taken from the answers at Got "is not a recognized Objective-C method" when bridging Swift to React-Native; the fact that it doesn't work, is because of the difference in the first argument labels.

    To make it work with your initial code you should write the first argument of your Swift to be without a name, like this:

    @objc
    func loginWithEmail(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
        //   the trick  ^
        resolve("This method is no longer troublesome")
    }
    

提交回复
热议问题