【问题标题】:@lvalue $T5' is not identical to 'AnyObject in Swift@lvalue $T5' 与 Swift 中的 'AnyObject' 不同
【发布时间】:2015-01-27 22:22:24
【问题描述】:

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

@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

        }
    }

【问题讨论】:

  • 试试for object in objects as [NSDictionary] {
  • @vacawama 我刚试了一下,得到了错误“无法分配给这个表达式的结果”

标签: ios arrays swift parse-platform


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    试试这个语法:

    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] {
    ...
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-06
      相关资源
      最近更新 更多