2

I am trying to implement the TradeIt ios SDK and I am not able to compile due to issues in the sdk.

let promises = self.getAllDisplayableLinkedBrokers().map {
        linkedBroker in
        return Promise<Void> { seal in
            linkedBroker.authenticateIfNeeded(
                onSuccess: seal.fulfill,
                onSecurityQuestion: onSecurityQuestion,
                onFailure: { tradeItErrorResult in
                             onFailure(tradeItErrorResult, linkedBroker)
                             seal.fulfill(())
                           }
            )
        }
}

on the line with onSuccess: seal.fulfill, there is an error: Cannot convert value of type '(Void) -> ()' to expected argument type '() -> Void'

The following is the definition for the authenticateIfNeeded method that details what it's expecting for onSuccess.

@objc public func authenticateIfNeeded(onSuccess: @escaping () -> Void, onSecurityQuestion: @escaping (TradeItSecurityQuestionResult,_ submitAnswer: @escaping (String) -> Void, _ onCancelSecurityQuestion: @escaping () -> Void) -> Void,
        onFailure: @escaping (TradeItErrorResult) -> Void
    ) -> Void {
        guard let error = self.error else {
                onSuccess()
                return
        }

        if error.requiresAuthentication() {
            self.authenticate(
                onSuccess: onSuccess,
                onSecurityQuestion: onSecurityQuestion,
                onFailure: onFailure
            )
        } else if error.requiresRelink() {
            onFailure(error)
        } else {
            onSuccess()
        }
}

I am developing a react native application and I need to create a react native module for ios for the TradeIt sdk. That is why I am not familiar with objective-c and have a steep learning curve ahead of me. Any help would be appreciated. Thank you!

2 Answers2

1

could you try this:

    return Promise<Void> { seal in
        linkedBroker.authenticateIfNeeded(
            onSuccess: seal.fulfill(()),
  • I'm happy to delete my answer, but I'd like you to expand this to be clearer (that's why I added an answer that elaborated on why this is necessary). The OP is not a Swift expert, and the `(())` syntax is a bizarre corner case of Swift that you should explain rather than give a code-only solution. Happy to upvote you proactively, and I'll delete my answer once you update. – Rob Napier Jun 05 '20 at 03:29
  • fair enough. Leave your answer for future reference. – workingdog support Ukraine Jun 05 '20 at 04:32
0
            onSuccess: seal.fulfill,

This line says to call seal.fulfill() on success. However, fulfill requires a value of the type you promised. You promised a Void (which is just another name for ()), so you need to pass that.

            onSuccess: { seal.fulfill(()) },

This syntax is a little unfortunate, which is why I generally avoid specializing on Void this way. I'm not very familiar with PromiseKit, but I would look and see if there's another tool that is designed for the "no useful return value" case than Promise<Void>. There may not be, but sometimes there's another name for it.

As a note, I don't see any Objective-C here. This is entirely Swift.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610