我正在尝试将变量放入我的PFObject(我正在使用Parse):
func retrieveScore() {
var query:PFQuery = PFQuery(className: "Score")
query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in
for varScore in objects! {
let scoreExtract:Int? = (varScore as? [PFObject]) as? Int
}
}
}
但它给了我这个错误:“从'[PFObject]'转换为无关类型'int'总是失败。
如何将对象提取到变量中?我需要一个数组?
谢谢。答案 0 :(得分:0)
您正在做的是首先将varScore
转换为Array
PFObject
,然后将Array
转换为Int
。如何将Array
转换为Int
?
如果对象包含Array
PFObject
,那么
func retrieveScore() {
var query:PFQuery = PFQuery(className: "Score")
query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in
for varScore in objects! {
let score = varScore as? PFObject
let youeIntPropertyValue = score.someIntProperty// a property in Score class/struct.
}
}
}