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!
could you try this:
return Promise<Void> { seal in
linkedBroker.authenticateIfNeeded(
onSuccess: seal.fulfill(()),
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.
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.