Created
February 24, 2017 14:42
-
-
Save douglastaquary/594530b2103e10d43c7ec4e9711b43e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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