@lvalue $T5' 与 Swift 中的 'AnyObject 不相同

@lvalue $T5' is not identical to 'AnyObject in Swift

我有一个自定义的 TableViewCell,它有一个标签和一个按钮。我有一个 Int 数组 groupVote,它包含将填充 UITableView 中的标签 voteScoreLabel 的值。当点击按钮 upVoteButtonPressed 时,使用标签更新单元格的相应值。但是在下面的代码中有一个错误(我已经把特定的行放在下面的代码中)显示:@lvalue $T5' is not identical to 'AnyObject!, when I want to update the value in Parse.这是什么意思,我该如何解决?

@IBAction func upVoteButtonPressed(sender: AnyObject) {
    println(groupVote[voteScoreLabel.tag])
    groupVote[voteScoreLabel.tag]=groupVote[voteScoreLabel.tag]+1
  var messageDisplayTwo = PFQuery(className:currentScreen)
    messageDisplayTwo.whereKey("identifier", equalTo:voteScoreLabel.tag )
    messageDisplayTwo.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]!, error: NSError!) -> Void in
        if error == nil{
            for object in objects {
                var textNumb=groupVote[self.voteScoreLabel.tag] as Int
                object["vote"]=textNumb //Error Right Here: @lvalue $T5' is not identical to 'AnyObject!


            }

        } else {
            // Log details of the failure

        }
    }

您需要将 objects 转换为 PFObject 的数组。

for object in objects as [PFObject] {
        var textNumb = groupVote[self.voteScoreLabel.tag] as Int
        object["vote"] = textNumb
}

试试这个语法:

query.findObjectsInBackgroundWithBlock{

            (objects: [AnyObject]!, error: NSError!) -> Void in


            if (error == nil) {
                // objects in results will only contain the playerName and score fields

                for object in objects as [PFObject] {
...
...