swift 无法分配给属性:'detailDic'是'let'常量

wydwbb8l  于 2023-05-05  发布在  Swift
关注(0)|答案(1)|浏览(209)

我的代码有问题,它告诉我“无法分配给属性:'detailDic'是一个'let'常量”,我的构建失败

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "detail" {
            if let indexPath = self.tableView.indexPathForSelectedRow {
                let dic = cities[indexPath.row]
                let detailVC = segue.destination as! DetailViewController
                detailVC.detailDic = dic
                
                
            }
        }
    }

我试过这个,得到这个错误“运算符'=='的结果未使用”,它运行,但它会崩溃

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "detail" {
            if let indexPath = self.tableView.indexPathForSelectedRow {
                let dic = cities[indexPath.row]
                let detailVC = segue.destination as! DetailViewController
                detailVC.detailDic == dic
                
                
            }
        }
    }
k2arahey

k2arahey1#

我发现了我的问题
我用了let detailDic = [String:String]()
最多为var detailDic = [String:String]()

相关问题