CountriesCollectionController

open class CountriesCollectionController : BaseCollectionController<CountriesCollectionController.ItemTuple>

A subclass of BaseCollectionController that shows a list of countries for selection in a CollectionViewController.

This CollectionController subclass retrieves a list of countries with states from the user defaults using the defaultsKey static property value. The list of countries retrieved from the user defaults is encoded with the following JSON format:

{
  "name": "<country_name>",
  "code": "<country_code>",
  "states": [
    {
      "label": "<state_label_or_name>",
      "code": "<state_code>"
    }
  ]
}

The country object contains a name with a string value of the name of the country, a code with a string value of the country code and an array of state objects.

The state object contains a label with a string value of the name/label of the state, and a code with a string value of the state code.

The default cell used is a CountryCollectionViewCell. Its nameLabel is used to display the country name. If the country name is empty, the code is displayed instead.

The countries displayed are sorted alphabetically by the country’s name. If the country’s name is empty, the country’s code is used instead for sorting.

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.
  • The key used to retrieve the list of encoded countries from the user defaults.

    The value of this is:

    "com.cheetahdigital.CountriesAndStates"
    

    Declaration

    Swift

    public static let defaultsKey: String
  • The typealias used for items in this collection controller.

    Declaration

    Swift

    public typealias ItemTuple = (name: String, code: String)
  • Declaration

    Swift

    override open var collectionViewLayout: UICollectionViewLayout { get }
  • The closure to be executed when an item is selected

    The parameters passed to this closure are two strings. The first string is the item name and the second string is the item code.

    Declaration

    Swift

    open var selectionClosure: ((String, String) -> Void)?
  • Declaration

    Swift

    override open func registerComponents()
  • Declaration

    Swift

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

UICollectionViewDataSource

  • Undocumented

    Declaration

    Swift

    override open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell

UICollectionViewDelegate

  • Undocumented

    Declaration

    Swift

    override open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)

ContentLoader

  • Undocumented

    Declaration

    Swift

    override open func loadContent()