魔法
从无到有召唤表格和集合
简介
DataSource
是一个嵌入式 DSL,用于使用 UITableViews 和 UICollectionViews 构建用户界面。您定义列表的结构,DataSource 将会自动遵守 UITableViewControllerDataSource
,UITableViewControllerDelegate
,UICollectionViewControllerDataSource
和 UICollectionViewControllerDelegate
。
例如,以下是如何创建一个简单的 UITableViewController 的示例
let vc = BlockTableViewController(
style: .grouped,
dataSource: DataSource(
sections: [
Section(
items: [
Item { (cell: BedazzledTableViewCell) in
cell.titleLabel.text = "Custom cells"
},
Item { (cell: SubtitleTableViewCell) in
cell.textLabel?.text = "Load any cell with ease"
cell.detailTextLabel?.text = "Sorcery automatically registers and loads the correct cell by using the class specified in the configure block."
cell.detailTextLabel?.numberOfLines = 0
}
]
)
],
middleware: [
Middleware.noCellSelectionStyle,
Middleware.separatorInset(UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0))
]
)
)
安装
魔法可以通过 CocoaPods 获得。要安装它,请简单地将以下行添加到您的 Podfile 中
pod "Sorcery"
作者
Adam Cumiskey,[email protected]
许可证
魔法遵循 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。