2017-04-09 101 views
0

我试图在火力使用此代码新的子添加到我的节点:dispatch_group_leave错误,同时增加新的子

@IBAction func likeButtonOnTouch(_ sender: Any) { 

    if ViewController.usersUid.count > 0 { 

     self.update() 

    } 
} 

func update() { 
    let child1: String = (FIRAuth.auth()?.currentUser?.uid)! 
    let ref = FIRDatabase.database().reference().child(child1).child("following") 


    let data1: [String:String] = [ViewController.usersUid[self.currentUser]: "true"] 

    ref.setValue(data1) 
} 

但是,当我按下按钮,我的这个错误的应用程序崩溃:

thread 1 exc_bad_instruction (code=1 subcode=0x100ef5c78)

在这条线:

ref.setValue(data1) 

我不知道这意味着什么,以及如何解决它。值已成功添加到我的数据库(!!!)最有趣的事情,但应用程序崩溃。请给我一个建议。

P.S.崩溃报告:

* thread #1: tid = 0xb503, 0x0000000100f11c78 libdispatch.dylib`dispatch_group_leave + 76, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x100f11c78) 
frame #0: 0x0000000100f11c78 libdispatch.dylib`dispatch_group_leave + 76 
frame #1: 0x00000001000a36f8 Elite Club`thunk + 68 at ViewController.swift:0 
frame #2: 0x00000001001bf8a4 Elite Club`__43-[FValueEventRegistration fireEvent:queue:]_block_invoke.57((null)=<unavailable>) + 88 at FValueEventRegistration.m:60 [opt] 
frame #3: 0x0000000100f0d258 libdispatch.dylib`_dispatch_call_block_and_release + 24 
frame #4: 0x0000000100f0d218 libdispatch.dylib`_dispatch_client_callout + 16 
frame #5: 0x0000000100f12280 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 1200 
frame #6: 0x000000019376e810 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 
frame #7: 0x000000019376c3fc CoreFoundation`__CFRunLoopRun + 1660 
frame #8: 0x000000019369a2b8 CoreFoundation`CFRunLoopRunSpecific + 444 
frame #9: 0x000000019514e198 GraphicsServices`GSEventRunModal + 180 
frame #10: 0x00000001996e17fc UIKit`-[UIApplication _run] + 684 
frame #11: 0x00000001996dc534 UIKit`UIApplicationMain + 208 
frame #12: 0x00000001000c04b8 Elite Club`main + 140 at AppDelegate.swift:15 
frame #13: 0x000000019267d5b8 libdyld.dylib`start + 4 
+0

'ref' is nil or'data1' is nil? – Paulw11

+0

@ Paulw11,no。我已通过在xcode控制台打印值并检查了数据已成功添加到我的数据库中的ref – Burning

+0

@NazmulHasan Hasan同样的错误 – Burning

回答

0

工作一整天后,我想通了。首先,您应该退出,然后再登录一次。这里是我的最终代码:

func update() { 

     do { 
      let ref = try FIRAuth.auth()?.signOut() 
     } 
     catch {} 

     let preferences = UserDefaults.standard 
     FIRAuth.auth()?.signIn(withEmail: preferences.object(forKey: "userName") as! String, password: preferences.object(forKey: "userPassword") as! String) { (user, error) in 

      if error == nil { 
       LoggingIn.userUID = (user?.uid)! 

       print(user?.uid ?? "not found") 
       print("You have successfully logged in") 

       let child1: String = (FIRAuth.auth()?.currentUser?.uid)! 
       let ref = FIRDatabase.database().reference().child(child1).child("following") 


       let data1: [String:String] = [ViewController.usersUid[self.currentUser] : "true"] 



       ref.setValue(data1) { (error, ref) -> Void in 

       } 

      } else { 


      } 
     } 
    } 
1

如果ViewController.usersUid[self.currentUser]不存在,请崩溃

你能试试这个方法:

let data1: [String:String] = [(ViewController.usersUid[self.currentUser] ?? "") : "true"] 

ref.setValue(data1) { (error, ref) -> Void in 

} 

更清洁的方式:

if let currentuser = ViewController.usersUid[self.currentUser] { 

    let data1: [String:String] = [currentuser : "true"] 

    ref.setValue(data1) { (error, ref) -> Void in 

    } 

} 
+0

不幸的是,同样的错误 – Burning

+0

@Burning可以检查请回答更新 –

+0

仍然有一个错误 – Burning