测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最新发布 | 2017 年 4 月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 kmk 维护。
要运行示例项目,克隆仓库,然后从 Example 目录运行 pod install
。
SectionedDatas 通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile 中
pod "SectionedDatas"
只需创建一个 SectionedDatas 或其子类实例,然后将包含分区的数据添加到其中。
private func createSectionDatasWithData() -> SectionedString {
let datas = SectionedDatas<String, String>()
datas.add(section: "section0", with: ["section0_data0", "section0_data1"])
datas.add(section: "section1", with: ["section1_data0", "section1_data1", "section1_data2"])
datas.add(section: "section2", with: ["section2_data0", "section2_data1", "section2_data2"])
datas.add(section: "section3", with: ["section3_data0"])
datas.add(section: "section4", with: ["section4_data0", "section4_data1", "section4_data2", "section4_data3", "section4_data4"])
datas.add(section: "section5", with: ["section5_data0", "section5_data1", "section5_data2", "section5_data3", "section5_data4"])
for i in 0 ..< 10 {
datas.add(section: "section6", with: "section6_data\(i)")
}
datas.add(section: "section7", with: "section7_data0")
for i in 0 ..< 20 {
datas.add(section: "section8", with: "section8_data\(i)")
}
datas.add(section: "section9", with: "section9_data0")
datas.add(section: "section9")
return datas
}
}
func numberOfSections(in tableView: UITableView) -> Int {
return self.datas.allSections().count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let ds = self.datas.allDatas(atSectionIndex: section){
return ds.count
}
return 0
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.datas.section(ofIndex: section)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
cell?.textLabel?.text = self.datas.allDatas(atSectionIndex: indexPath.section)?[indexPath.row]
return cell!
}
//MARK: -
public func add(section: S)
public func add(section: S, with data: D)
public func add(section: S, with datas: [D])
//MARK: -
public func section(ofData data: D) -> S?
public func section(ofIndex index: Int)->S?
//MaRK: -
public func contains(section: S) -> Bool
public func contains(data: D, within section: S) -> Bool
public func contains(data: D) -> Bool
//MARK: -
public func index(of data: D, within section: S) -> Int?
public func index(ofSection section: S) -> Int?
public func indexOfAll(fromIndex indexWithinSection: Int, withinSection sectionIndex: Int) -> Int?
public func indexOfAll(fromData data: D, withinSection section: S) -> Int?
//MARK: -
public func allSections() -> [S]
public func allDatas(ofSection section: S) -> [D]?
public func allDatas(atSectionIndex sectionIndex: Int) -> [D]?
public func allDatas() -> [D]
//MARK: -
public func removeAll()
public func remove(at indexOfSection: Int)
public func remove(section: S)
public func remove(data: D, within section: S)
//MARK: -
public func enumerate(invoke: (S, D)->())
public func enumerate(section: S, invoke: (D)->())
//MARK: -
public func makeIterator() -> SectionedIterator<S, D>
SectionedDatas 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。