BaseCollectionController

open class BaseCollectionController<T> : NSObject, CollectionController

An abstract base class for providing data and handling actions for a CollectionViewController.

This is a generic NSObject conforming to UICollectionViewDataSource, UICollectionViewDelegate, UISearchBarDelegate and ContentLoader protocols.

This class is to be subclassed to comply to a specific behavior.

The associated type of this class will be used to initialize it’s CollectionDataProvider property. By default, the init(collecitonView:) initialization method assigns the collection view property and sets it up using the setupCollectionView method.

This class also supports data filtering through UISearchBarDelegate searchBar(_:,textDidChange:) method. It calls the updateFilteredData to update the filtered CollectionDataProvider property. The filteredData(with:) is called to filter the data using the search string.

Note

Due to what maybe seems to be a bug with the Swift, methods not initially in the superclass and implemented in the subclass may not be executed. To get around this, the method needs to have an @objc attribue.
  • Declaration

    Swift

    open weak var statefulViewController: StatefulViewController?
  • Declaration

    Swift

    open var collectionViewController: CollectionViewController? { get }
  • The data provider of the CollectionController.

    Declaration

    Swift

    open var provider: CollectionDataProvider<T>
  • An optional filtered data provider of the CollectionController.

    Declaration

    Swift

    open lazy var filteredProvider: CollectionDataProvider<T> { get set }
  • Determines whether the data is supposed to be filtered or not.

    Declaration

    Swift

    open var isFiltered: Bool
  • The collection view to provide data and handle actions for.

    Declaration

    Swift

    open weak var collectionView: UICollectionView? { get set }
  • The layout for the collection view.

    Declaration

    Swift

    open var collectionViewLayout: UICollectionViewLayout { get }
  • Represents whether the collection controller is fetching content.

    Declaration

    Swift

    open var isFetching: Bool
  • Undocumented

    Declaration

    Swift

    override public init()
  • Returns a newly initialized collection controller with the specified collection view to provide data and handle actions for.

    Declaration

    Swift

    public init(collectionView: UICollectionView? = nil)

    Parameters

    collectionView

    The collection view to associate with.

    Return Value

    The initialized collection controller.

  • Sets up the collection view’s layout, dataSource, delegate properties, and registers components to the collection view.

    Declaration

    Swift

    open func setupCollectionView()
  • Register components to the collection view.

    Declaration

    Swift

    open func registerComponents()
  • Returns the item at the specified index path from either the provider or the filteredProvider depending on the value of isFiltered.

    Declaration

    Swift

    open func dataItem(at indexPath: IndexPath) -> T?

    Parameters

    indexPath

    The index path for the item.

    Return Value

    Returns the item data.

  • Updates the filtered data given the search term.

    If the search term is empty, this sets isFiltered to false. Otherwise, this removes all data from the filtered data provider and gets new filtered data from filterData(with:) then sets isFiltered to true. The collection view is then reloaded afterwards.

    Declaration

    Swift

    open func updateFilteredData(with searchTerm: String)

    Parameters

    searchTerm

    The search term to use as filter.

  • Returns the filtered data from the data provider.

    Declaration

    Swift

    open func filteredData(with searchTerm: String) -> [T]

    Parameters

    searchTerm

    The search term to use as filter.

    Return Value

    Returns the filtered data.

UICollectionViewDataSource

UICollectionViewDelegate

ContentController

UISearchBarDelegate