我的应用程序在第一次打印后崩溃

            print("got here")
            ref.child("Used").observeSingleEvent(of: .value, with: { (snapshot) in
                print("got here?")
                // do something
            })


但是,从脚本前面的相同位置进行相同的调用时,它不会崩溃

ref.child("Used").observeSingleEvent(of: .value, with: { (snapshot) in

        // Check if exists
        if snapshot.hasChild(self.TextField.text!) {
            let joinInfo = ["info"     : self.TextField.text!]
            self.Information = joinInfo
            self.performSegue(withIdentifier: "Segue", sender: self)
        } else {
            // TODO Alert error
        }
    })


来自第一个代码块的完整代码:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "Segue" {
            if let destination = segue.destination as? ViewController {
                // Create a dispatch group to sync all Firebase call
                print("got here ")
                ref.child("Used").observeSingleEvent(of: .value, with: { (snapshot) in
                    print("got here?")

                })
            }
    }
}


我收到的错误消息是:fatal error: unexpectedly found nil while unwrapping an Optional value2017-01-24 15:48:23.845240 A[10696:2902570] fatal error: unexpectedly found nil while unwrapping an Optional value

堆:

    0x10081d1e4 <+96>:  nop
0x10081d1e8 <+100>: mov    x0, x25
0x10081d1ec <+104>: mov    x1, x24
0x10081d1f0 <+108>: mov    x2, x23
0x10081d1f4 <+112>: mov    x4, x8
0x10081d1f8 <+116>: bl     0x100710b80               ; function signature specialization <preserving fragile attribute, Arg[1] = [Closure Propagated : reabstraction thunk helper from @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> () to @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@out ()), Argument Types : [@callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> ()]> of generic specialization <preserving fragile attribute, ()> of Swift.StaticString.withUTF8Buffer <A> ((Swift.UnsafeBufferPointer<Swift.UInt8>) -> A) -> A
->  0x10081d1fc <+120>: brk    #0x1

最佳答案



ref.child("Used").observeSingleEvent(of: .value, with: { (snapshot) in
                    print("got here?")

            })


进入上一个ref.调用。将joinInfo从let更改为var。

关于swift - 尝试获取Firebase数据时获得“解开可选值时为零”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41841027/

10-13 04:12