Deepak Thakur Deepak Thakur - 2 months ago 22
Swift Question

'NSFastEnumerator.Element' (aka 'Any') has no subscript members

I was going through this appcoda blog and came across a function where I have to get indices of visible rows. I am learning and implementing

Swift 3
/
Xcode 8
. I get
No subscript members
error for the following function.

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)
}
}


How do I get object of
currentSectionCells
array whose object for key is "
isVisible
" here?

Answer

You need to specify the type of your array cellDescriptors to [[[String:Any]]] like this way.

for currentSectionCells in cellDescriptors.objectEnumerator().allObjects as! [[[String:Any]]]{
    var visibleRows = [Int]()

    for row in 0..<currentSectionCells.count {
        if currentSectionCells[row]["isVisible"] as! Bool == true { 
            visibleRows.append(row)
        }
    }
    visibleRowsPerSection.append(visibleRows)
}
Comments