DequeuableRegistrable 版本 0.1.5

DequeuableRegistrable 版本 0.1.5

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2017 年 1 月
SwiftSwift 版本3.0
SPM支持 SPM

Fernando Ortiz 维护。



  • Fernando Ortiz

DequeuableRegistrable

简介

DequeuableRegistrable 是一组简单的协议扩展,允许在不使用不安全的字符串或显式转换的情况下注册和排队单元格以及页脚/页眉(从 UITableView 或 UICollectionView)。

示例项目

要运行示例项目,请克隆 repo,然后首先从 Example 目录运行 pod install

要求

  • iOS 9.0 或更高版本
  • Swift 3.0 或更高版本

安装

DequeuableRegistrable 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile

pod "DequeuableRegistrable", :git => "https://github.com/fmo91/DequeuableRegistrable/"

概览

DequeuableRegistrable 将注册从这样变得容易

tableView.register(UINib(nibName: "DogCell", bundle: nil), forCellReuseIdentifier: "DogCell")

到这样

DogCell.register(in: tableView)

排队也这样简单

let cell = tableView.dequeueReusableCell(withIdentifier: "DogCell") as! DogCell

到这样

let cell = DogCell.dequeue(from: tableView) 
// cell is DogCell, not UITableViewCell. It's already casted.

唯一需要做的是这样

extension DogCell: Registrable, Dequeuable {}

使用方法

DequeuableRegistrable 包含三个简单的协议

  1. Identifiable:它允许通过提供键字符串来识别任何类型的对象。对于单元格,该字符串是可重用标识符。
  2. Dequeuable:继承自 Identifiable。它允许使用 Identifiable 协议提供的可重用标识符从 UICollectionViewUITableView 排队单元格。
  3. Registrable:继承自 Identifiable。它允许使用 Identifiable 协议提供的可重用标识符和在 Registrable 协议中要求的 nib 对象在 UICollectionViewUITableView 中注册单元格。

所有这些协议都有扩展,返回与类名匹配的默认值。因此,例如,如果您有一个 ABCCell 类,那么其默认可重用标识符将是 "ABCCell",其 UINib 将是 UINib(nibName: "ABCCell")

作者

Fernando Ortiz,[email protected]

许可证

DequeuableRegistrable 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。