我在以下行中收到以下错误:“ let imgFile = object["imageFile"] as 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)
}
}
}
我得到的运行时错误:
尽管错误出现在这一行“ let imgFile = object["imageFile"] as PFFile ”,但您还可以看到解析数据库类确实具有名称完全相同的字段“ imgFile ”