私は、ユーザーがメッセージをタップするたびに1によってFirebase変数のスコアをインクリメントすることになっているコードのこの部分を持っている:私はラインでエラーNo '+' candidates produce the expected contextual result type 'AnyObject?'
を取得していますがSwift: 'AnyObject?'型のオペランドには、バイナリ演算子 '+'を適用できません。そして、 'int型
override func collectionView(collectionView: JSQMessagesCollectionView!, didTapMessageBubbleAtIndexPath indexPath: NSIndexPath!) {
super.collectionView(collectionView, didTapMessageBubbleAtIndexPath: 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
currentData.value = currentData.value + 1
return FIRTransactionResult.successWithValue(currentData)
}) { (error, committed, snapshot) in
if let error = error {
print(error.localizedDescription)
}
}
currentData.value = currentData.value + 1
私は理解できません。
誰が私は素晴らしいだろう、このタイプのエラーを修正するのに役立つことができれば
(それはBinary operator '+' cannot be applied to operands of type 'AnyObject?' and 'Int'
を言います)私はそのようなcurrentData.value = currentData.value + 1 as! Int
などcurrentData.value as! Int = currentData.value + 1
として整数としてキャストしようとしたが、スウィフトは、それはしていません!
を私はあなたのコードを試してみましたが、それは誤りで私のプログラムがクラッシュ: '型の値をキャストすることができませんでした「nsnullを」(0x19fe50bc0「)のNSNumber」(0x19fe5b900).' –
にしてくださいあなたの価値はいくつかの価値を持っているかどうかチェックする前に? NSNumber/Int/NSIntegerを持っているのはどんな種類の価値があるのでしょうか? –
あなたのデータ型を教えてください –