This multiplatform library helps to get the user's selected items from different sections using high composability.
I'm using it in my personal app CLOC: Tasks & Time Tracker to create/edit tasks, here is a quick preview:
public protocol ItemType: Hashable { var title: String { get } }The core model that is used widely in the project.
For now, it is using a typealias AnyItem which is equal to ItemType. It is added for further development.
public protocol ItemsLoader { associatedtype Item: AnyItem typealias FetchItemsResult = Result<[Item], Error> typealias FetchItemsCompletion = (FetchItemsResult) -> Void func loadItems(for section: Int, completion: @escaping FetchItemsCompletion) -> CancellableFetch }Abstraction of loading data for each section.
public protocol ItemsContainer: AnyObject { associatedtype Item: AnyItem var delegate: ItemsContainerDelegate? { get set } var selectionType: ItemsContainerSelectionType { get } var items: [Item] { get } var selectedItems: [Item]? { get } var allowAdding: Bool { get } func select(at index: Int) func deselect(at index: Int) func add(item: Item) func removeSelection() }Abstraction of controlling items in a container.
It is provided with DefaultItemsContainer which do the things needed, such as:
- Selection
- Deselection
- Prevent selection more than maximum limit
- Delegation
public protocol SectionedViewProtocol: AnyObject { associatedtype View var view: View { get } var selectedSectionIndex: Int { set get } var numberOfSections: Int { get } var onSectionChange: (() -> Void)? { set get } func reload(withTitles: [String]) }Abstraction of a view with sections, e.g. UISegmentedControl.
public protocol ResourceListViewProtocol: AnyObject { associatedtype View associatedtype CellController: SelectableCellController var view: View { get } var onSelection: ((Int) -> Void) { get set } var onDeselection: ((Int) -> Void) { get set } func reloadData(with: [CellController]) func allowMultipleSelection(_ isOn: Bool) func allowAddNew(_ isOn: Bool) func deselect(at: Int) }Abstraction of a view with list of items e.g. UITableView, UICollectionView.
- You can head to iOS Snapshot Tests and learn how to use it in your iOS project. There are a lot of mocking which helps you conform your custom views and models to the protocols of this library.
- There is a public class called
ZZComposableInputwhich you can get started.
Please feel free to open an issue to:
- Repoert a bug
- Request a feature
- Ask for help
And also you can help improving this project by opening a PR.
ZZComposableInput is available under the MIT license. See the LICENSE file for more info.

