Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public protocol InitializableCell {
- associatedtype T
- init(item: T)
- }
- public typealias ACCollectionNodeCellAction = (_ collectionNode: ASCollectionNode, _ indexPath: IndexPath, _ object: Any) -> Void
- open class ASCollectionNodeAdapter<Provider: CollectionDataProvider, Cell: ASCellNode>:
- NSObject,
- ASCollectionDataSource,
- ASCollectionDelegate
- where Cell: InitializableCell, Provider.T == Cell.T
- {
- // MARK: - Delegates
- public var didSelectCell: ACCollectionNodeCellAction?
- // MARK: - Private Properties
- let provider: Provider
- let collectionNode: ASCollectionNode
- // MARK: - Lifecycle
- init(collectionNode: ASCollectionNode, provider: Provider) {
- self.collectionNode = collectionNode
- self.provider = provider
- super.init()
- setUp()
- }
- func setUp() {
- collectionNode.dataSource = self
- collectionNode.delegate = self
- }
- // MARK: - ASCollectionDataSource
- public func numberOfSections(in collectionNode: ASCollectionNode) -> Int {
- return provider.numberOfSections()
- }
- public func collectionNode(_ collectionNode: ASCollectionNode, numberOfItemsInSection section: Int) -> Int {
- return provider.numberOfItems(in: section)
- }
- public func collectionNode(_ collectionNode: ASCollectionNode, nodeBlockForItemAt indexPath: IndexPath) -> ASCellNodeBlock {
- return { [weak self] () -> ASCellNode in
- guard let `self` = self, let item = self.provider.item(at: indexPath) else {
- return ASCellNode()
- }
- return Cell.init(item: item)
- }
- }
- // MARK: - ASCollectionDelegate
- }
Add Comment
Please, Sign In to add comment