【问题标题】:Swift 3 - Type 'Any' has no subscript membersSwift 3 - 类型'Any'没有下标成员
【发布时间】:2017-01-19 17:04:08
【问题描述】:

我将我的项目升级到 Swift 3 并遇到了这个错误:

let cellDescriptor = cellDescriptors[(indexPath as NSIndexPath).section][indexOfVisibleRow] as! [String: AnyObject]

我在这一行遇到错误:

Type 'Any' has no subscript members

我该如何解决这个问题?我不知道该怎么做。我尝试将第一部分转换为 NSDictionary,然后它告诉我 IndexPath 类型的 indexPath 无法转换为 NSIndexPath

【问题讨论】:

  • cellDescriptors 是什么类型的?它没有将其识别为数组。
  • 向我们提供有关 cellDescriptors 的更多详细信息。编译器可能无法推断出第二种类型,因为您使用了两次下标。

标签: ios arrays swift nsdictionary nsindexpath


【解决方案1】:

NSIndexPath 已经被 IndexPath 替换了,所以那部分应该变简单了

cellDescriptors[indexPath.section]

对于剩下的问题,您是如何定义 cellDescriptors 的?分两步进行可能会更容易

let firstPart = cellDescriptors[indexPath.section] as! MyCellDescriptor
let cellDescriptor = firstPart[indexOfVisibleRow]

【讨论】:

  • 虽然这是真的,但不能解决当前问题。
猜你喜欢
  • 1970-01-01
  • 2017-02-06
  • 1970-01-01
  • 1970-01-01
  • 2017-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多