Skip to content

Instantly share code, notes, and snippets.

@douglastaquary
Created February 24, 2017 14:42
Show Gist options
  • Select an option

  • Save douglastaquary/594530b2103e10d43c7ec4e9711b43e1 to your computer and use it in GitHub Desktop.

Select an option

Save douglastaquary/594530b2103e10d43c7ec4e9711b43e1 to your computer and use it in GitHub Desktop.
import UIKit
final class DashboardCollection: UICollectionView {
var didSelectIndicator: ((Behavior) -> Void)?
fileprivate var customDatasource: DashboardCollectionDataSource?
fileprivate var customDelegate: DashboardCollectionDelegate?
convenience init() {
self.init(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
}
override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: layout)
customDelegate = DashboardCollectionDelegate(self)
customDatasource = DashboardCollectionDataSource(items: [], collectionView: self, delegate: customDelegate!)
self.backgroundColor = UIColor.white
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension DashboardCollection {
func updateItems(_ items: [Tray]) {
customDatasource?.updateItems(items)
}
}
extension DashboardCollection: DashboardDelegate {
func didSelectIndicator(at index: IndexPath) {
if let indicator = customDatasource?.items[index.section].behaviors?[index.row] {
didSelectIndicator?(indicator)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment