Старая версия кода перед XCode 7 Beta 3: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]» не имеет элемент с именем «фи lterByIndex '
Что изменилось?
Я согласен с @Arkku, код, похоже, работает нормально. Я думаю, если бы вы могли привести пример 'namesArr' и' dupes', которые могли бы помочь сузить проблему (и обязательно включить типы для них). – justinpawela