Joseph Toronto Joseph Toronto - 2 months ago 31
Swift Question

Swift 3.0 array "contains" argument compiler error

Here is the statement that's causing trouble. This worked perfectly in Swift 2.2 but is not working in 3.0 and Xcode 8.

keys = keys
.enumerated()
.filter { !indexesToRemove.contains($0.index) }
.map { $0.element }


Right at
$0.index
xCode is throwing a compiler error:

Value of tuple type '(offset: Int, element: Any)' has no member 'index'


As far as I know $0 represents objects in the
keys
array. What tuple is it talking about?

Answer

index has been changed to offset in Swift 3 (don't ask me why):

keys = keys
    .enumerated()
    .filter { !indexesToRemove.contains($0.offset) }
    .map { $0.element }
Comments