次の行で以下のエラーが発生しています: " 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 "のフィールドがあることもわかります。