gpt4 book ai didi

ios - 添加新 child 时出现 dispatch_group_leave 错误

转载 作者:行者123 更新时间:2023-11-28 15:44:39 30 4
gpt4 key购买 nike

我正在尝试使用以下代码向我在 firebase 中的节点添加一个新子节点:

@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)

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

附言崩溃报告:

* 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

最佳答案

如果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

}

}

关于ios - 添加新 child 时出现 dispatch_group_leave 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43304034/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com