我在下面的行中收到以下错误:" 让imgFile = object [" imageFile"]作为PFFile "
代码:
func getRightLevelInfo() {
var query = PFQuery(className: "userstatus")
query.whereKey("username", equalTo: PFUser.currentUser().username)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
println("Found something")
for object in objects {
println(object.objectId)
let lastSuccessfulLevel = object["lastSuccessfulLevel"] as Int
let nextLevel = lastSuccessfulLevel + 1
let score = object["score"] as Int
println("lastSuccessfulLevel = " + String(lastSuccessfulLevel) + ", Score = " + String(score))
var queryLevel = PFQuery(className: "puzzledata")
queryLevel.whereKey("lastleveldone", equalTo: String(nextLevel))
queryLevel.findObjectsInBackgroundWithBlock {
(levels: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
for level in levels {
self.wordAnswer = level["wordAnswer"] as String
self.wordJumbled = level["wordJumbled"] as String
println("For this level, wordAnswer = " + self.wordAnswer + ", wordJumbled = " + self.wordJumbled)
let imgFile = object["imageFile"] as PFFile
imgFile.getDataInBackgroundWithBlock({
(imageData: NSData!, error: NSError!) -> Void in
if (error == nil) {
let image = UIImage(data:imageData)?
println("Got Image Successfully")
} else {
println("ERROR in getting image")
}
})//getDataInBackgroundWithBlock - end
}
} else {
println("%@", error) //couldn't find level data
}
}
}
}
else {
println("%@", error)
}
}
}
我得到的运行时错误:
虽然错误在这一行" 让imgFile = object [" imageFile"]为PFFile ",您还可以看到解析数据库class确实具有完全相同名称的字段" imgFile "
答案 0 :(得分:1)
看起来像是一个错字,你应该替换
let imgFile = object["imageFile"] as PFFile
与
let imgFile = level["imageFile"] as PFFile