swift - 尝试摆脱写时复制的存在主义

标签 swift swift3 xcode9 copy-on-write

当我尝试将字典作为参数传递给子类中定义的方法时,出现了这个新的运行时错误。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  let cell = tableView.dequeueReusableCell( withIdentifier: "cell", for: indexPath) as! Cell
  cell.configure(self.data[indexPath.row] as Dictionary<String, AnyObject>) // FAILS HERE STATING: "Attempting to move out of a copy-on-write existential"

  ...
  ...
}

这曾经在 Swift 2.3 上运行得很好

如何解决这个问题?

PS:我在 Mac 10.12.6 上运行 Xcode 9.0(9A235)(使用 Swift 3.2)

最佳答案

最终使用[String: Any]而不是Dictionary<String, AnyObject> ,它开始工作了。字典类型转换的奇怪问题。

关于swift - 尝试摆脱写时复制的存在主义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47350039/

相关文章:

ios - array.insert 不会保存元素

swift - 如何正确地将 WKWebView 嵌入自定义 UIView 中?

ios - 有没有办法通过 Alamofire 上传 doc、pdf 文件?

swift - 批量修复 Xcode 9 或 9.1 中的数百个 "#selector not exposed to Objective-C"错误

ios - 扩展 Storyboard 中可用的对象数量

ios - 从 objective-c 调用 swift 类(派生自 NSObject 类)init

swift - Swift 中的单例

ios - UIActivityIndi​​catorView 未显示在 web View 中

swift - 使用 GCD 在 Swift 3 中同步属性

ios - 在静态 iOS 框架上执行 XCUITests