![](/img/trans.png)
[英]Cannot convert value of type 'Void' to expected argument type '(String) -> Void'
[英]Cannot convert value of type '(Void) -> ()' to expected argument type '() -> Void'
我正在嘗試實現 TradeIt ios SDK,但由於 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(())
}
)
}
}
在與onSuccess: seal.fulfill,
出現錯誤: Cannot convert value of type '(Void) -> ()' to expected argument type '() -> Void'
以下是authenticateIfNeeded
方法的定義,詳細說明了它對 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()
}
}
我正在開發一個 react native 應用程序,我需要為 TradeIt sdk 創建一個用於 ios 的 react native 模塊。 這就是為什么我不熟悉 objective-c 並且前面有一條陡峭的學習曲線。 任何幫助,將不勝感激。 謝謝!
你可以試試這個:
return Promise<Void> { seal in
linkedBroker.authenticateIfNeeded(
onSuccess: seal.fulfill(()),
onSuccess: seal.fulfill,
這條線說成功時調用seal.fulfill()
。 但是, fulfill
需要您承諾的類型的值。 你承諾了一個 Void (這只是()
的另一個名稱),所以你需要通過它。
onSuccess: { seal.fulfill(()) },
這種語法有點不幸,這就是為什么我通常避免以這種方式專門研究 Void。 我對 PromiseKit 不是很熟悉,但我會看看是否有另一種工具是為Promise<Void>
設計的“沒有有用的返回值”的情況。 可能沒有,但有時它還有另一個名字。
作為說明,我在這里看不到任何 Objective-C。 這完全是 Swift。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.