“AnyObject.Protocol”类型的值不符合预期的字典值类型“AnyObject”

时间:2015-12-19 17:39:59

标签: ios swift parse-platform

我正在尝试使用Parse将单位保存到玩家的军队中。此代码抛弃了error

  

“AnyObject.Protocol”类型的值不符合预期的字典值类型“AnyObject”

我想我必须以某种方式施放dictionary。不知道我做错了什么。

  let unitParse = PFObject(className: "playerArmies", dictionary: ["\(PFUser)":AnyObject])
  unitParse["UnitName"] = selectedUnit.name
  unitParse["CurrentHP"] = selectedUnit.hitPoints
  unitParse["MaxHP"] = selectedUnit.hitPointsMax
  unitParse.saveInBackgroundWithBlock {
    (success: Bool, error: NSError?) -> Void in
    if (success) {
      // The object has been saved.
    } else {
      // There was a problem, check error.description
    }
  }

1 个答案:

答案 0 :(得分:2)

问题在于此代码:

["\(PFUser)":AnyObject]

您正在将类类型AnyObject设置为字典的值。你需要在那里传递实际对象。你的问题不清楚,你需要通过什么对象。我想你想要的东西:

["PFUser" : "\(PFUser)"]