2016-09-22 118 views
2

接收Value of type 'IndexSet' has no member 'enumerateIndexesUsingBlock' enumerateIndexesUsingBlock錯誤。Swift 3.0:類型'IndexSet'的值沒有成員'enumerateIndexesUsingBlock'

/** 
Extension for creating index paths from an index set 
*/ 
extension IndexSet { 
    /** 
    - parameter section: The section for the created NSIndexPaths 
    - return: An array with NSIndexPaths 
    */ 
    func bs_indexPathsForSection(_ section: Int) -> [IndexPath] { 
     var indexPaths: [IndexPath] = [] 

     self.enumerateIndexesUsingBlock { (index:Int, _) in 
      indexPaths.append(IndexPath(item: index, section: section)); 
     } 

     return indexPaths 
    } 
} 
+0

如果使用換的,而不是塊? (index,\ index),value = \(value)「) }對於(index,value)in self.enumerated() { } – Che

回答

2

基金會類型NSIndexSet具有enumerateIndexesUsingBlock 方法。從斯威夫特3對應的覆蓋類型IndexSet是一個集合,所以你可以地圖每個 指數的IndexPath

extension IndexSet { 
    func bs_indexPathsForSection(_ section: Int) -> [IndexPath] { 
     return self.map { IndexPath(item: $0, section: section) } 
    } 
} 
相關問題