更新解析表中的值我编写了这行代码:
object["score"] = self.selectedScore
但它给了我错误:
cannot assign value of type 'Int' to a value of type 'AnyObject?!'
所以我考虑将self.selectedScore
转换为类型AnyObject?!
这就是我做到的:
if let var castScore = self.selectedScore as! AnyObject?
{
object["score"] = castScore
}
但仍出现另一个错误,指出castScore
的类型为AnyObject?
object["score"]
类型为AnyObject?!
有没有办法让castScore
成为AnyObject?!
类型?
表格跟踪:
CODE:
//test
var taskQuery = PFQuery(className: "Track")
//run query
taskQuery.findObjectsInBackgroundWithBlock({
(success:[AnyObject]?, error: NSError?) -> Void in
if let objects = success {
for object in objects {
var name = sucess["taskName"]
var score = sucess["score"]
var unwrappedName = ""
var unwrappedScore = ""
if let name = name {
unwrappedName = "\(name!)"
}
if let score = score {
unwrappedScore = "\(score!)"
}
if unwrappedName == Track {
object["score"] = self.selectedScore //#ERROR
sucess.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
println("Object has been saved.")
}
}
//trackMgr.addTrack(unwrappedName, score: unwrappedScore.toInt()!, view: false)
}
}
})
//test
答案 0 :(得分:1)
我认为当你使用它时,你应该打开success!["score"]
。
if let _ = sucess["score"] {
var score = success!["score"]
}
答案 1 :(得分:-1)
删除该行末尾的问号。
if let var castScore = self.selectedScore as! AnyObject
{
object["score"] = castScore
}