gpt4 book ai didi

swift - 期望返回 '' 的闭包中缺少返回

转载 作者:搜寻专家 更新时间:2023-11-01 07:17:11 25 4
gpt4 key购买 nike

我有以下功能:

override func collectionView(_ collectionView: JSQMessagesCollectionView!, didTapMessageBubbleAt indexPath: IndexPath!) {

super.collectionView(collectionView, didTapMessageBubbleAt: indexPath)
let data = self.messages[indexPath.row]

print("They tapped: " + (data.text) + "- " + (data.senderDisplayName))

rootRef.child("messages").child(data.senderId).child("score").runTransactionBlock({ (currentData: FIRMutableData) -> FIRTransactionResult in
// Set value and report transaction success
if let myValue = currentData.value as? Int{
currentData.value = myValue + 1
return FIRTransactionResult.success(withValue: currentData)
}


}) { (error, committed, snapshot) in
if let error = error {
print(error.localizedDescription)
}
}

}

但是我一直收到错误:

Missing return in a closure expected to return 'FIRTransactionResult'

在这一行的开头:

}) { (error, committed, snapshot) in

但据我所知,我在函数的前几行中返回了所需的元素。

有人可以帮我弄清楚我需要返回什么来修复这个错误吗?

谢谢。

最佳答案

由于我的问题发生在 if 语句之后,我需要在正确的 FIRTransactionResult 表单中包含一个失败案例,例如:

else {
return FIRTransactionResult.abort()
}

它解决了我的问题。

问题解决了!

关于swift - 期望返回 '' 的闭包中缺少返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41530302/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com