SwiftSimpleKit 1.0.0

SwiftSimpleKit 1.0.0

Jonah Pelfrey维护。



  • 作者:
  • Jonah Pelfrey

Swift Simple Kit

Core

ControllerView

  • 将UI代码从视图控制器中移出
  • 为控制器中的视图引用提供静态类型
class ControllerView: UIView {
    required init(controller: UIViewController)
    func configureSubviews() {}
}

Controller

  • 要求视图类型是符合ControllerView类型的泛型类型
  • 负责实例化视图
class Controller<View: ControllerView>: UIViewController {
    var childView: View!
    func configure() {}
}

Simple List

简单列表单元格兼容

  • 允许声明式单元格属性的接口
  • 属性包括视图属性和数据要求
  • 可哈希要求允许数据类型符合DiffableDataSources
public protocol SimpleListCellCompatible: class {
    associatedType DataObjectType: Hashable
    func setData(_ data: DataObjectType, _ indexPath: IndexPath)
    
    static var reuseIdentifier: String { get }
    static var height: CGFloat { get }
    static var spacing: CGFloat { get }
    static var contentInsets: NSDirectionalEdgeInsets { get }
}

简单列表视图

  • 继承自ControllerView的视图
  • 包含一个与frame范围绑定单个的收藏视图
typealias CompatibleCell = UICollectionViewCell & SimpleListCellCompatible

class SimpleListView<Cell: CompatibleCell>: ControllerView {
    var collectionView: UICollectionView
    func createLayout() -> UICollectionViewLayout
}

简单列表控制器

  • 继承自控制器
  • 继承自SimpleListView的视图需要显式类型
  • 遵循CellCompatible的单元格需要显式类型
class SimpleListController<Cell: CellCompatible>: Controller<SimpleListView<Cell>>, UICollectionViewDelegate {
    enum Section: CaseIterable {}
    var dataSource: UICollectionViewDiffableDataSource<Section, Cell.DataObjectType>!
    func updateDataSource(_ data: [Cell.DataObjectType])
}