简体   繁体   English

Swift 3.0数组“包含”参数编译器错误

[英]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. 这在Swift 2.2中工作得很好,但在3.0和Xcode 8中却不起作用。

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

Right at $0.index xCode is throwing a compiler error: 就在$0.index抛出编译器错误:

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

As far as I know $0 represents objects in the keys array. 据我所知,$ 0代表keys数组中的对象。 What tuple is it talking about? 它在说什么元组?

index has been changed to offset in Swift 3 (don't ask me why): index已在Swift 3中更改为offset (不要问我为什么):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM