Last active
November 14, 2020 05:01
-
-
Save nashysolutions/999ef0b7337f5d99b9ba7bf425be5b71 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
| class MenuViewController: UIViewController { | |
| let table = MenuTableHandler() | |
| var categories: [MenuCategory] = [] | |
| var selections = Set<MenuItem>() | |
| fileprivate var searchText: String? { | |
| didSet { | |
| if oldValue == searchText { return } | |
| categories = MenuOption.allCases.map { | |
| let category = $0.makeCategory(searchText: searchText) | |
| category.dataSource = self | |
| return category | |
| } | |
| table.update(with: categories, animate: false) | |
| } | |
| } | |
| } | |
| extension MenuViewController: MenuCategoryDataSource { | |
| func menuItemIsSelected(_ item: MenuItem) -> Bool { | |
| return selections.contains(item) | |
| } | |
| } | |
| final class MenuItem: Hashable, Comparable { | |
| unowned let category: MenuCategory | |
| var isSelected: Bool { | |
| return category.dataSource?.menuItemIsSelected(self) ?? false | |
| } | |
| } | |
| protocol MenuCategoryDataSource: AnyObject { | |
| func menuItemIsSelected(_ item: MenuItem) -> Bool | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment