EXEC_BAD_INSTRUCTION 尝试从 Parse 获取图像时

EXEC_BAD_INSTRUCTION when trying to get image from Parse

我在以下行中收到以下错误:“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”,也可以看到parse database class 确实有一个名称完全相同的字段“imgFile

这看起来像是一个拼写错误,您应该将其替换

let imgFile = object["imageFile"] as PFFile

let imgFile = level["imageFile"] as PFFile