iOS 和 Parse 抛出异常:"unexpectedly found nil"

iOS and Parse throwing exception: "unexpectedly found nil"

我在 Xcode 6.4 上做一些 iOS 应用程序,我使用 Parse 作为后端,一切都很好,直到我尝试添加 Parse 从中获取的消息对象到凝视阵列。

错误:

fatal error: unexpectedly found nil while unwrapping an Optional value

问题是我不知道 nil 是什么意思,因为我已经打开了所有值,或者至少我是这么认为的,帮帮忙??

代码:

var mensajes:[String]!

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    println("\(PFUser.currentUser()!.username!)")
    menuLabel.text =  "Bienvenido \(PFUser.currentUser()!.username!)"
    /*
    var query = PFQuery(className: "Alumnos")

    query.whereKey("nombre", hasSuffix: "1")

    query.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]?, error: NSError?) -> Void in
        if error == nil {
            println("No error")
            println("we have \(objects!.count)")

            if let object = objects as? [PFObject] {
                for obj in object {
                    println("\(obj.objectId) ----")
                    println(obj)
                    println(obj["nombre"] as! String + "*****")
                }
            }
        } else {

            println("a misterious error has appeared \(error!) \(error!.description)")
        }

    } */

    var avisosQuery = PFQuery(className: "Alumnos")

    if let papa = PFUser.currentUser() {
        avisosQuery.whereKey("userId", equalTo: papa)

        avisosQuery.findObjectsInBackgroundWithBlock {
            (alumnos: [AnyObject]?, error: NSError?) -> Void in

            if error == nil {

                println("No Error we have \(alumnos?.count) students")

                var grupos: PFObject? = nil

                if let obj = alumnos as? [PFObject] {
                    for alum in obj {
                        println(alum["nombre"])
                        //println(alum["grupoId"])
                        //println(alum)
                        grupos = alum["grupoId"] as? PFObject
                        println(grupos!)


                        var secondQuery = PFQuery(className: "Avisos")

                        secondQuery.whereKey("grupoId", equalTo: grupos!)

                        secondQuery.findObjectsInBackgroundWithBlock {
                            (avisos: [AnyObject]?, error: NSError?) -> Void in

                            if error == nil {

                                println("No error we are home free \(avisos?.count)")

                                if avisos?.count > 0 {

                                    if let avisoArray = avisos as? [PFObject] {
                                        for av in avisoArray {
                                            println(av["texto"]!)

                                            if let msg: AnyObject = av["texto"] {

                                                println(msg)
                                                self.mensajes.append(msg as! String)

                                            }
                                        }
                                    }
                                }
                            } else {

                                println("something got busted, mate")
                            }
                        }
                    }
                }
            } else {

                println("we screw something up")
            }
        }
    }

}

而且我正处于 Parse 的学习阶段,这就是为什么在 viewDidLoad() 中我只是在尝试一些东西。

if let papa = PFUser.currentUser() 

The problem is in that line we are not get the userid so technically you are looking for a null value

正确的代码:

let papa = PFUser.currentUser().objectId

试一试