Swift 3 setValuesForKeys Dictionary Error

时间:2017-12-31 19:45:41

标签: swift xcode firebase

我想在我的Firebase数据库上获取用户ID并将这些用户标识打印到表格视图中。我将用户ID存储在Firebase上的位置元组中。但是当我运行我的应用程序时,我在第25行收到信号SIGABRT错误。问题出在哪里?有人帮我吗?

    chatInfo.swift
    class ChatInfo: UITableViewController {

    let cellId = "cellId"
    var users = [User] ()

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Geri", style: .plain, target:self, action: #selector(handleCancel))
        fetchUser()
    }
    func handleCancel() {

        dismiss(animated: true, completion: nil)

    }
    func fetchUser() {

        Database.database().reference().child("locations").observe(.childAdded, with: {(snapshot) in

            if let dictionary = snapshot.value as? [String: Any] {

                let user = User()
                user.setValuesForKeys(dictionary) //ERROR
                self.users.append(user)

                DispatchQueue.main.async(execute: {
                    self.tableView.reloadData()
                })
            }

        } , withCancel: nil)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func numberOfSections(in tableView: UITableView) -> Int {
        return users.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = UITableViewCell(style: .subtitle, reuseIdentifier: cellId)

        let user = users[indexPath.row]
        cell.textLabel?.text = user.userId
        return cell
    }
    }
    User.swift
    class User: NSObject {


    var userId: String?
    }

0 个答案:

没有答案