Tales123 Tales123 - 4 months ago 330
Swift Question

NSFastEnumerationIterator.Element (aka Any) has no subscript members

after updating xcode to 8 version, I got this error
enter image description here

searchArray = allArray.filter({$0["test"] as? String == findCode
let resultText: NSString = ($0["test"] as? String)
return (resultText.range(of: searchText, options: NSString.CompareOptions.caseInsensitive).location) != NSNotFound
}) as NSArray!

Any thoughts?


The ultimate source of your problem is this line:

var allArray : NSArray!

NSArray is an Objective-C class. You are trying to write Objective-C code in Swift. Don't. This is Swift. Use Swift types! Write Swift code!

This is presumably an array of something. Swift needs to know what that is. For example, if this is an array of dictionaries, than its type would be [[AnyHashable:Any]]. If you use Swift types, your code will just work, because Swift will know what the elements of your arrays are.