【发布时间】:2015-07-11 13:15:57
【问题描述】:
XCode 7 Beta 3 之前的旧版本代码:
extension Array {
func filterByIndex<S: SequenceType where S.Generator.Element == Int>(indices: S) -> [T] {
return Array(PermutationGenerator(elements: self, indices: indices))
}
func find(includedElement: T -> Bool) -> Int? {
for (idx, element) in self.enumerate() {
if includedElement(element) {
return idx
}
}
return nil
}
}
XCode 7 Beta 3 之后的新版本代码:
extension Array {
func filterByIndex<S: SequenceType where S.Generator.Element == Int>(indices: S) -> [Element] {
return Array(PermutationGenerator(elements: self, indices: indices))
}
func find(includedElement: Element -> Bool) -> Int? {
for (idx, element) in self.enumerate() {
if includedElement(element) {
return idx
}
}
return nil
}
}
但是现在当我写这行时,函数 filterByIndex 给了我一个错误:
let names = (namesArr as! [String]).filterByIndex(dupes)
“[String]”没有名为“filterByIndex”的成员
有什么变化?
【问题讨论】:
-
我同意@Arkku,代码似乎工作得很好。我想如果你能举一个例子
namesArr和dupes可能有助于缩小问题范围(并确保包括这些类型)。
标签: arrays swift xcode7-beta3