【发布时间】:2016-09-22 13:42:21
【问题描述】:
我正在浏览这个appcoda blog 并遇到了一个函数,我必须在其中获取可见行的索引。我正在学习和实施Swift 3 / Xcode 8。以下函数出现No subscript members 错误。
func getIndicesOfVisibleRows() {
visibleRowsPerSection.removeAll()
for currentSectionCells in cellDescriptors {
var visibleRows = [Int]()
for row in 0...((currentSectionCells as! [[String: AnyObject]]).count - 1) {
if currentSectionCells[row]["isVisible"] as! Bool == true { //Get compile time error here
visibleRows.append(row)
}
}
visibleRowsPerSection.append(visibleRows)
}
}
如何在此处获取 currentSectionCells 数组的对象,其键对象为“isVisible”?
【问题讨论】:
-
你确定有 两个 for 循环吗?
-
@vadian:是的,有两个 for 循环。请参考链接博客中的功能。
-
我无法理解 Swift 教程仍然建议不相关的集合类型,例如
MSMutableArray和丑陋的老式 C 样式循环。 Swift 中有很多更好、更有效的方法。