从最近更新的 Xcode 7.3 开始,我开始看到这条消息。我正在使用循环中的序列,如下所示:
for (index, product) in EnumerateSequence(self.products) {
//Do something with the product
//Do something with the index
}
注释在EnumerateSequence
.
如果您想知道他们为什么要添加此警告并要删除EnumerateSequence.init
,那是因为它EnumerateSequence
是该方法的实现细节enumerate
。他们希望您使用enumerate
而不是依赖于它的实现方式。
经过一些测试,这是从 Swift 2.2 开始使用的解决方案,以防您想同时使用 theindex
和 the object
:
for (index, product) in self.products.enumerate() {
//Do something with the product
//Do something with the index
}
删除EnumerateSequence
并使用您的Array.enumerate()
方法