Joseph Toronto Joseph Toronto - 1 year ago 126
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
.filter { !indexesToRemove.contains($0.index) }
.map { $0.element }

Right at
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
array. What tuple is it talking about?

Answer Source

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

keys = keys
    .filter { !indexesToRemove.contains($0.offset) }
    .map { $0.element }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download