Swift Xcode/firebase,搜索栏“;以NSException类型的未捕获异常终止;

Swift Xcode/firebase,搜索栏“;以NSException类型的未捕获异常终止;,swift,firebase-realtime-database,searchbar,Swift,Firebase Realtime Database,Searchbar,我现在已经试了好几个小时来找出这个问题,但是我对xcode还是新手,所以 我制作了一个搜索栏,我想为它添加用户配置文件。 (在我更改搜索栏之前,搜索栏工作正常) 为了能够搜索用户,请单击并输入包含详细信息的新视图控制器。 但是当我运行它时,模拟器崩溃,搜索栏不工作 在viewDidLoad中,我添加了: databaseRef.child("Buyers").queryOrdered(byChild: "Personnr").observe(.childAdded, with: {(snapsh

我现在已经试了好几个小时来找出这个问题,但是我对xcode还是新手,所以

我制作了一个搜索栏,我想为它添加用户配置文件。 (在我更改搜索栏之前,搜索栏工作正常) 为了能够搜索用户,请单击并输入包含详细信息的新视图控制器。 但是当我运行它时,模拟器崩溃,搜索栏不工作

在viewDidLoad中,我添加了:

databaseRef.child("Buyers").queryOrdered(byChild: "Personnr").observe(.childAdded, with: {(snapshot) in
    self.usersArray.append(snapshot.value as? NSDictionary)

        let key = snapshot.key
        let snapshot = snapshot.value as? NSDictionary
        snapshot?.setValue(key, forKey: "Personnr")
“Personnr”是用户。(这对所有用户都是不同的)

这会将它们带到新的viewController:

override func prepare(for segue: UIStoryboardSegue, sender: (Any)?) {

    let visKunderProfileViewController = segue.destination as!
    ProfileViewController

    visKunderProfileViewController.loggedInUser = self.loggedInUser


    if let indexpath = tableView.indexPathForSelectedRow {
        let user = usersArray[indexpath.row]
        visKunderProfileViewController.otherUser = user
    }

}
在新的viewController中,我添加了:

override func viewDidLoad() {
    super.viewDidLoad()

    self.databaseRef = Database.database().reference()

    databaseRef.child("Buyers").child((self.loggedInUser!.uid)).observe(.value, with: { (snapshot) in

        self.loggedInUserData = snapshot.value as?
            NSDictionary

        self.loggedInUserData?.setValue(self.loggedInUser!.uid, forKey: "Personnr")

    }) { (error) in
        print(error)
    }

    databaseRef.child("Buyers").child(self.otherUser?["Personnr"] as! String).observe(.value, with: { (snapshot) in

        let uid = self.otherUser?["Personnr"] as! String
        self.otherUser = snapshot.value as? NSDictionary
        self.otherUser?.setValue(uid, forKey: "Personnr")

    }) { (error) in
        print(error)
    }

    self.Navn.text = self.otherUser?["Fornavn"] as? String
我得到的消息是:“以NSException类型的未捕获异常终止”

我检查了所有按钮和插座,所有设备都已连接,没有显示其他错误

请询问您是否还有其他需要知道的事情。
谢谢

请从日志中输入更多有关崩溃的详细信息。您可能想要添加一个
异常断点
,方法是转到Xcode的左侧导航器,然后单击
断点导航器(位于最后一个选项卡的第二个)。然后单击底部的
+
符号并添加一个
异常断点
。请从日志中输入有关崩溃的更多详细信息。您可能想要添加一个
异常断点
,方法是转到Xcode的左侧导航器,然后单击
断点导航器(位于最后一个选项卡的第二个)。然后单击底部的
+
符号并添加一个
异常断点