Cheetah CES Docs Portal

Navigation
Home
GitHub
Email
Corporate Site


Cheetah Digital UI Kit

« Back to iOS Kit References

Configuration

This kit doesn’t require additional configurations, once added on the project it is already good to go.

Localization

To replace or override a string, add the string key in your application’s Localizable.strings and provide a new value. See all string keys used in Cheetah Loyalty UI Kit Localization.

Usage

This kit is composed of different classes for different uses like View Controllers, View Components and other components that help developers for faster UI related development. This section will provide explanation on how and when to use the classes.

View Controllers

Cheetah Digital UI Kit contains custom commonly used view controllers for Cheetah Loyalty Applications which help developers by providing convenience and faster application developments.

These are view controller classes that are used for displaying a list, detail, app info and so on

NibViewController

A subclass of UIViewController that can be initialized with a specified nib name or a nib named the same as its class name. This served as the base class of all view controllers that is used in the Cheetah Digital UI Kit. It can be initialized by either providing a nib name or not. Initializing without providing a nib name will return a newly initialized NibViewController with the nib file named the same as its class name.

This class also contains a method called setup. This method is called at the end of the viewDidLoad call.

StatefulViewController

A NibViewController subclass that manages and displays states of content. This view controller handles states of loading content by displaying the appropriate child view controller depending on the value of its state property. Usually this view controller contains a class that conforms to ContentController protocol.

StatefulViewController has 2 important properties:

  • state which is of type Enum and has a default value of .loading.
  • contentController which is an optional object that conforms to ContentController protocol.

This class overrides the setup method in it’s superclass(NibViewController) which logs the screen using the Analytics and calls the loadContent() method of it’s contentController.

The contentController is an object that conforms to the ContentController protocol which represents a class that loads and refreshes content.

CollectionViewController

This is a subclass of StatefulViewController which is used for displaying collection view. This class contains a collectionController property which is an optional object that conforms to CollectionController protocol. It also contains a refresh control which calls the refreshContent() method of its collectionController.

CollectionController represents a type for providing data and handling actions for a CollectionViewController. It is a protocol that inherits from ContentController and has an added property collectionView which is an optional UICollectionView. It also conforms to UICollectionViewDataSource, UICollectionViewDelegate, and UISearchBarDelegate. There are already available classes inside the Cheetah Digital UI Kit that conforms to CollectionController protocol:

  • BaseCollectionController - An abstract base class for providing data and handling actions for a CollectionViewController. 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.

    CollectionDataProvider is a class that represents data to be used in a collection view. This class manages a two dimensional array of an associated item type. The first dimension of the array serves as an indicator of the section while the second dimension are the items in the section.

  • ListCollectionController - A subclass of BaseCollectionController that serves as a base class that handles paginated list behavior for a CollectionViewController.

    This CollectionController subclass manages paginated lists by keeping track of the current and loaded pages as well as pre-fetching succeeding pages. This shows a loading cell at the end of the list when it has not yet reached the last page. Also by default, the layout returns a ListCollectionViewFlowLayout which is similar to a table view.

    By default, this uses ListItemCell for its cells. The associated type can conform to the ListItemCellPresentable to be able to configure the cells to present content of the type.

    When subclassed, the registerComponents and collectionView(collectionView:cellForItemAt:) can be overridden to bypass usage of the ListItemCell The typical usage of this class when subclassed is:

    • Optionally override registerComponents to register cells and reusable views.
    • Override loadContent(completion:) to fetch and update content.
    • Optionally override collectionView(collectionView:cellForItemAt:) for configuring cells.
    • Override collectionView(collectionView:didSelectItemtAt:) for cell select actions.

For this example we will create a Challenges list.

import CheetahDigitalCore
import CheetahDigitalUI

class ChallengesListController: ListCollectionController<Challenge> {

    override func loadContent() {
    isFetching = true

    if provider.numberOfItems(in: 0) == 0 {
        statefulViewController?.state = .loading(message: nil)
    }

            ChallengesAPI.getChallenges(with: ["page": currentPage + 1, "layout": "mobile_list"],
                                        completion: { [weak self] result in
                                            guard let self = self else { return }
                                            switch result {
                                            case .success(let response):
                                                self.totalItems = response.listInfo?.totalEntries ?? 0
                                                let challenges = response.value
                                                DispatchQueue.main.async {
                                                    if challenges.isEmpty {
                                                        // Change state value to .empty
                                                        return
                                                    }
                                                    self.updateCollection(with: challenges)
                                                    self.statefulViewController?.state = .content
                                                }
                                            case .failure(let error):
                                                DispatchQueue.main.async {
                                                        // Change state value to .error
                                                    })
                                                }
                                            }
                                    self.isFetching = false
    })
    }

extension Challenge: ListItemCellPresentable {
    public var imageURL: URL? {
        return URL(string: thumbImageUrl)
    }

    public var image: UIImage? {
        return nil
    }

    public var title: String {
        return heading
    }

    public var subtitle: String {
        return "\(metricAmount)\(displayName)"
    }

    public func configureListCell(_ cell: ListItemCell) {
        // Use this method for further customization of cell
    }
}

Using the code above these are the necessary steps to use a ListCollectionController:

  1. Import the necessary frameworks.
  2. Create a subclass of ListCollectionController and provide its associated type, in this case a Challenge model.
  3. Override the loadContent() method. This is where the data will be retrieved, most of the time loadContent() method contains an API call from the Cheetah Digital Core kit. Don’t forget to change the state of its statefulViewController depending on the data. 4 If the cell that will be use is ListItemCell conform the associated type to the ListItemCellPresentable and provide implementation for the properties and method.
  • CarouselCollectionController - A subclass of BaseCollectionController that serves as a base class that handles carousel behavior for a CollectionViewController. This CollectionController subclass manages a carousel-like content layout with a page control. The page control receives events to navigate through the content.

    By default, this uses CarouselItemCell for its cells. The associated type can conform to the CarouselItemCellPresentable to be able to configure the cells to present content of the type.

    When subclassed, the registerComponents and collectionView(collectionView:cellForItemAt:) can be overridden to bypass usage of the CarouselItemCell. The typical usage of this class when subclassed is:

    • Optionally override registerComponents to register cells and reusable views.
    • Override loadContent(completion:) to fetch and update content.
    • Optionally override collectionView(collectionView:cellForItemAt:) for configuring cells.
    • Override collectionView(collectionView:didSelectItemtAt:) for cell select actions.

The implementation of the ListCollectionController and CarouselCollectionController is almost the same, the only difference is the cell that will be used which is CarouselItemCell and CarouselItemCellPresentable.

Note: BaseCollectionController should be used as a superclass for creating collection views that is not a list nor carousel.

Countries and States CollectionController

CountriesCollectionController is 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.

CountryCollectionViewCell is the default collection view cell used by the CountriesCollectionController to display the list of countries. This cell contains a single label that is used to display the name of the country.

The steps on using CountriesCollectionController are:

  1. Initialize a CountriesCollectionController
  2. Provide a selectionClosure in the initialzed country collection controller.
  3. Initialize a CollectionViewController and provide the collectionController using the initialized object in the first step.
  4. Call the loadContent method of the initialized CountriesCollectionController
  5. Show the initialized CollectionViewController.

StatesCollectionController is a subclass of CollectionController that shows a list of states for selection in a CollectionViewController. This CollectionController subclass displays a list of states based from the value of the country code property. The states are retrieved from the user defaults using the defaultsKey static property value.

StateCollectionViewCell is the default collection view cell used by the StatesCollectionController to display the list of states. This cell contains a single label that is used to display the name/label of the state.

Note: Usage of StatesCollectionController is identical to the CountriesCollectionController except StatesCollectionController should be initialized instead of CountriesCollectionController.

On starting of an app, the app should have a setup for retrieving countries and states to the server and put the results on User Defaults.

DetailViewController

A StatefulViewController subclass that manages a generic detail view. This view controller serves as the base design of a detail view. An object conforming to the DetailController protocol is the data provider and action handler of this view controller.

DetailController is a protocol that represents a type for providing data and handling actions for a DetailViewController. This protocol inherits from the ContentController protocol.

DetailPresentable protocol represents a type that is presentable through a DetailViewController. This is similar to ListItemCellPresentable or CarouselItemCell presentable where you will conform the class to these properties to provide values to its details.

For this example we will create a Challenge Detail

import CheetahDigitalCore
import CheetahDigitalUI

class ChallengeDetailController: DetailController {

    var statefulViewController: StatefulViewController?
    var detailProvider: DetailPresentable?

    var id: Int

    init(id: Int) {
        self.id = id
    }

    func actionButtonPressed(_ actionButton: UIButton) {
        // Handle events when the action button is pressed
    }

    func loadContent() {
        ChallengesAPI.getChallenge(id: id,
                                 with: ["layout": "mobile_detail"],
                                    completion: { [weak self] result in
                                    guard let self = self else { return }
                                    switch result {
                                    case .success(let apiResponse):
                                        self.detailProvider = apiResponse.value
                                        guard let challengeDetailViewController = self.statefulViewController
                                            as? DetailViewController else { return }
                                        DispatchQueue.main.async {
                                            challengeDetailViewController.setupDetails()
                                            self.statefulViewController?.state = .content
                                        }
                                    case .failure(let error):
                                        DispatchQueue.main.async {
                                            // Change state value to .error
                                            })
                                        }
                                    }
        })
    }

    func refreshContent() {
        loadContent()
    }
}

extension Challenge: DetailPresentable {
    public var detailImage: UIImage? {
        return nil
    }

    public var detailImageUrl: String {
        return imageUrl
    }

    public var detailHeading: String {
        return heading
    }

    public var detailSubheading: String {
        return subheading
    }

    public var detailBody: String {
        return body
    }

    public var detailPoints: String {
        return "\(metricAmount) \(metricDisplayName)"
    }

    public var detailPeriod: String {
        return "\(startPeriod) - \(endPeriod)"
    }

    public var detailActionButtonTitle: String {
        return "Enter"
    }

}

Based on the code above the steps on using DetailViewController are:

  1. Import the necessary frameworks.
  2. Create a class conforming to DetailCollectionController and provide the required properties and methods.
  3. Provide the loading of data in the loadContent() method, most of the time loadContent() method contains an API call from the Cheetah Digital Core kit. Don’t forget to change the state of its statefulViewController depending on the data and call the setupDetails() of its detail view controller.
  4. Conform the object that will be use to display the data, in this case a Challenge struct.

SegmentedViewController

A NibViewController subclass that manages segmented views. This includes a segmented control that receives value changed events to change the shown view inside its container view. Data and selection actions are managed by an object conforming to SegmentedController which is assigned to the segmentedController property.

SegmentedController is a protocol that Represents a type which provides data and handling for actions for a SegmentedViewController.

For this example we will create a segmented view for Rewards and Redemptions list

import CheetahDigitalUI

struct RewardsSegmentedController: SegmentedController {

    let segments: [UIViewController] = [//Initialize a reward list view controller,
                                        //Initialize a redemption list view controller
                                        ]

    func numberOfSegments() -> Int {
        segments.count
    }

    func viewControllerForSegment(atIndex index: Int) -> UIViewController? {
        segments[index]
    }

    func titleForSegment(atIndex index: Int) -> String? {
        switch index {
        case 0:
            return "Reward.Rewards".localized
        case 1:
            return "Reward.Redeemed".localized
        default:
            return nil
        }
    }

    func didSelectSegment(atIndex index: Int, of segmentedViewController: SegmentedViewController) {}
}

Based on the code above the steps on creating a SegmentedViewController are:

  1. Import the necessary frameworks.
  2. Create a class conforming to SegmentedController protocol and provide the required methods.
  3. To use it initialize a SegmentedViewController and use an instance of the created class that conforms to SegmentedController protocol as the value of the segmentedController parameter.

WebViewController

A NibViewController subclass that displays web content which conforms to WKNavigationDelagate and contains a WKWebView and a UIProgressView.

The necessary steps on using WebViewController are:

  1. Create an instance of WebViewController.
  2. Provide the value of the URL.
  3. Show the created instance of WebViewController.

A subclass of CollectionViewController that shows a list of menu items with a log out button. This view controller should be provided with a MenuCollectionController class or subclass.

MenuCollectionController is a subclass of CollectionController which displays the Menu for selection in a MenuViewController. This utilizes ListCollectionViewFlowLayout which imitates the table view layout. By default, this uses MenuItemCell for its cells. The associated type should conform to the MenuItemCellPresentable to be able to configure the cells to present content of the type.

MenuItemCell is a general collection view cell for Menu content. This is the default collection view cell used by the MenuCollectionController to display the list of Menu.

MenuItemCellPresentable is a protocol that represents a type that is presentable through a MenuItemCell.

import CheetahDigitalCore
import CheetahDigitalUI

class CheetahMenuViewController: MenuViewController {

    override class var nibName: String {
        return "MenuViewController"
    }

    class var cheetahMenuItems: [MenuItemCellPresentable] {
        return [
            MenuItem.profile,
            MenuItem.messages,
            MenuItem.punchCards,
            MenuItem.referral,
            MenuItem.scan,
            MenuItem.terms,
            MenuItem.faqs,
            MenuItem.privacy,
            MenuItem.feedback,
            MenuItem.appInfo
        ]
    }

    convenience init(in main: MainViewController) {
        let menuItems = CheetahMenuViewController.cheetahMenuItems

        let menuCollectionController = MenuCollectionController(items: menuItems)

        menuCollectionController.logOutClosure = { (menuViewController) -> Void in
            // Provide logout closure
        }

        menuCollectionController.selectionClosure = { (menuViewController, item) -> Void in
            // Provide on selection closure
        }

        self.init(collectionController: menuCollectionController)
        self.mainNavigator = main
    }

    class func selectionAnimation(for menuItem: MenuItem?,
                                  with mainVC: MainViewController) -> (() -> Void)? {
                                      // Handle navigation
    }
}

enum MenuItem {
    case profile
    case messages
    case punchCards
    case referral
    case scan
    case terms
    case faqs
    case privacy
    case feedback
    case appInfo

    init?(stringValue: String) {
        switch stringValue {
        case "Menu.Profile".localized:
            self = .profile
        case "Menu.Messages".localized:
            self = .messages
        case "PunchCards.PunchCards".localized:
            self = .punchCards
        case "Menu.Referral".localized:
            self = .referral
        case "Menu.Scan".localized:
            self = .scan
        case "Menu.Terms".localized:
            self = .terms
        case "Menu.Faqs".localized:
            self = .faqs
        case "Menu.Privacy".localized:
            self = .privacy
        case "Menu.Feedback".localized:
            self = .feedback
        case "Menu.AppInfo".localized:
            self = .appInfo
        default:
            return nil
        }
    }

    var stringValue: String {
        switch self {
        case .profile:
            return "Menu.Profile".localized
        case .messages:
            return "Menu.Messages".localized
        case .punchCards:
            return "PunchCards.PunchCards".localized
        case .referral:
            return "Menu.Referral".localized
        case .scan:
            return "Menu.Scan".localized
        case .terms:
            return "Menu.Terms".localized
        case .faqs:
            return "Menu.Faqs".localized
        case .privacy:
            return "Menu.Privacy".localized
        case .feedback:
            return "Menu.Feedback".localized
        case .appInfo:
            return "Menu.AppInfo".localized
        }
    }
}

extension MenuItem: MenuItemCellPresentable {
    var image: UIImage? {
        return nil
    }

    var name: String {
        return stringValue
    }

    func configureMenuCell(_ cell: MenuItemCell) {
        cell.name.text = stringValue
        cell.name.setTextStyle(.body)
        cell.name.textColor = .primary
        cell.image.isHidden = true
    }
}

Based on the code above the steps on using MenuCollectionViewController are:

  1. Import the necessary frameworks.
  2. Create a subclass of MenuCollectionViewController and provide the required properties and methods.
  3. Create an enum for the menu items and conform it to MenuItemCellPresentable protocol.
  4. Create an instance of MenuCollectionController using the created enum.
  5. Provide the necessary closures to the instance of MenuCollectionController.
  6. Initialize a MenuViewController using the created instance of MenuCollectionController.

ScannerViewController

A NibViewController subclass that scans codes using the device’s camera. This view controller captures codes from the device’s camera then the code is passed into the captureAction closure(((ScannerViewController, String) -> Void)?) property. This class also conforms to AVCaptureMetadataOutputObjectsDelegate protocol. By default, the accepted codes are QR, EAN-8,EAN-13 (including UPC-A), and PDF417 codes.

AppInfoViewController

A NibViewController subclass that is use for displaying the info of the application. This displays the app name, version, build, Model info the the current device and system version.


View Components

There are components that help developers on creating other UI related components such Image picker, Alerts, Selection Buttons, etc.

ImagePickerPresenter

A wrapper class for setting up the presentation of an UIImagePickerController by a designated view controller. This wrapper class only accepts media types of image or movie.

This has a protocol for delegation which is ImagePickerPresenterDelegate. It is a protocol that represents a type that receives selection and cancel events from a ImagePickerPresenter.

// This assumes that the view controller(self) conforms to `ImagePickerPresenterDelegate`
let imagePicker = ImagePickerPresenter(presentingViewController: self, delegate: self)
imagePicker.present(with: .image)

AlertViewController

A container NibViewController that contains an AlertEmbeddableViewController.

AlertEmbeddableViewController is a NibViewController that can be embedded into an AlertViewController. The Cheetah Digital UI Kit already offers classes that conforms to this protocol:

  • GenericAlertViewController - An AlertEmbeddableViewController that can display a heading message, a subheading message, and a dynamic count of buttons in a UIStackView
  • LoadingAlertViewController - An AlertEmbeddableViewController that shows a UIActivityIndicatorView and a loading message.
  • UpgradeCheckViewController - An AlertEmbeddableViewController that displays a full screen view that forces/asks the user to upgrade the application to its current version

For convenience Cheetah Digital UI Kit has an extension for AlertViewController that has static methods for creating different alerts.

/// Returns an `AlertViewController` with an embedded `GenericAlertViewController`
public static func message(heading: String, subheading: String = "", actionText: String = "Generic.Okay".localized, isFullScreen: Bool = false, action: (() -> Void)? = nil) -> AlertViewController

/// Returns an `AlertViewController` with an embedded `GenericAlertViewController`
public static func confirmation(heading: String, subheading: String = "", confirmText: String = "Generic.Confirm".localized, cancelText: String = "Generic.Cancel".localized, isFullScreen: Bool = false, action: ((Int) -> Void)? = nil) -> AlertViewController

/// Returns an `AlertViewController` with an embedded `UpgradeCheckViewController`
public static func forcedUpgradeCheck(heading: String = "UpgradeCheck.UpgradeRequired".localized, subheading: String = "UpgradeCheck.NewVersionAvailable".localized, upgradeNowText: String = "UpgradeCheck.UpgradeNow".localized, appLink: String, isFullScreen: Bool = true) -> AlertViewController

/// Returns an `AlertViewController` with an embedded `UpgradeCheckViewController`
public static func upgradeCheck(heading: String = "UpgradeCheck.SuggestedUpgrade".localized, subheading: String = "UpgradeCheck.NewVersionAvailable".localized, upgradeNowText: String = "UpgradeCheck.UpgradeNow".localized, upgradeLaterText: String = "UpgradeCheck.UpgradeLater".localized, appLink: String, isFullScreen: Bool = true) -> AlertViewController

/// Returns an `AlertViewController` with an embedded `LoadingAlertViewController`
public static func loading(loadingText: String? = nil, isFullScreen: Bool = false) -> AlertViewController

SelectionButtons

Subclass of UIButton that can be use for providing selections to users. Cheetah Digital UI Kit provides different selection Button styles:

  • Checkbox - A subclass of SelectionButton use that lets a user have a binary choice.
  • RadioButton - A subclass of Checkbox that has an observer to other radio buttons within the same group.
  • RatingButton - A subclass of SelectionButton that serves as a rating button that has an observer to other rating buttons within the same group.

To use these simply change the custom class of a UIButton in the Identity Inspector in the Nib/Storyboard or initialize these views programmatically.

TextInput

Cheetah Digital UI Kit provides classes for text inputs which can be use instead of UITextView or UITextField. These are the available text inputs:

For Textviews:

  • GrowingTextView - A UIScrollView that contains a GrowingInternalTextView and it has the capability to automatically adjust its height and become scrollable when needed. This also has a delegate protocol GrowingTextViewDelegate.
  • FloatingTextView - A subclass of GrowingTextView that has similar behaviour found on android.

For Textfields:

  • FloatingTextField - A textfield that has a similar behaviour found on android.
  • FloatingTextFieldWithIcon - A subclass of FloatingTextField that contains a UIImage either on the left or right side.

To use these simply change the custom class of a UIButton in the Identity Inspector in the Nib/Storyboard or initialize these views programmatically.


Represents a type which can navigate to a view controller. The code below shows the method of Navigator protocol.

In the case of a UIViewController conforming to the Navigator protocol, a default implementation of the navigate(to:,modally:,animated:,completion:) is provided. In this default implementation, the UIViewController conforming to the Navigator protocol calls the appropriate navigation method depending on whether the navigation is modal or not. If the navigation is modal, it presents the destination view controller by calling the present(_, animated:, completion:). Otherwise, if the navigation is not modal, the navigation controller of the view controller will push the destination view controller by calling pushViewController(_, animated:, completion:). If the navigation is not modal and there is no existing navigation controller, this does nothing.

Image Loader

Represents a type that loads an image for an image view with a URL. This is the protocol used for loading images across Cheetah Digital Kits. An enum CheetahImageLoader contains a static property default which is of type ImageLoader. This is nil by default and should be provided a value on the setup of the app so the loading of images in Cheetah Digital Kits will work correctly.

This is the sample setup of ImageLoader

class AppImageLoader: ImageLoader {

    static var imagePlaceholder: UIImage?

    func loadImage(for imageView: UIImageView, with urlString: String, completion: ImageLoaderCompletion? = nil) {
        guard let url = URL(string: urlString) else {
            completion?(.failure(URLError(URLError.badURL)))
            return
        }
        loadImage(for: imageView, with: url, completion: completion)
    }

    func loadImage(for imageView: UIImageView, with url: URL, completion: ImageLoaderCompletion?) {
        let dataTask = URLSession.shared.dataTask(with: url, completionHandler: { (data, _, error) in
            if let data = data,
                let image = UIImage(data: data) {
                DispatchQueue.main.async {
                    imageView.image = image
                    completion?(.success(image))
                }
                return
            }

            if let error = error {
                DispatchQueue.main.async {
                    completion?(.failure(error))
                }
            }
        })
        dataTask.resume()
    }
}

Note: Somewhere in the app preferably in the AppDelegate, the value of the default property of CheetahImageLoader should be changed using the instance of the created class that conforms to ImageLoader protocol.

Analytics

Analytics of Cheetah Digital UI Kit has 2 parts: AnalyticsLogger and AnalyticsManager:

  • AnalyticsLogger - Represents a type that is able to log analytics events or screens.
  • AnalyticsManager - This represents a class that manages analytics logs. Objects conforming this protocol must call observeAnalyticsLogs. By default, the observeAnalyticsLogs sets up the conforming object to observe notifications with names of Notification.Name.logEvent and Notification.Name.logScreen. The selector for the Notification.Name.logEvent notification is the logEvent(from:) method, while the selector for the Notification.Name.logScreen is logScreen(from:) method. This protocol is best to be conformed by the AppDelegate of an app. And then implementing the logEvent(from:) and logScreen(from:) methods with calls to the designated analytics service.

Native Extensions

These are the collection of methods and properties that are available for developers from formatting date, formatting strings, etc.

UIColor

  • var hexDescription: String - Returns the hex description of an instance UIColor
  • var hexWithAlphaDescription: String - Returns the hex and alpha description of an instance UIColor.
  • static var error: UIColor - This instance of UIColor will get its value from the error color of the Theme.
  • static var primary: UIColor - This instance of UIColor will get its value from the Primary color of the Theme.
  • static var secondary: UIColor - This instance of UIColor will get its value from the Secondary color of the Theme.
  • static var primaryVariant: UIColor - This instance of UIColor will get its value from the Accent color of the Theme.
  • static var textColor: UIColor - This instance of UIColor will get its value from the text color of the Theme.
  • convenience init(hex: String?) - Returns an instance of a UIColor using a hex string.

UIView

  • var cornerRadius: CGFloat - The corner radius of the view
  • func embed(subview: UIView) - Embeds a subview.
  • func isContainedWithin(_ other: UIView) -> Bool - Checks if the view is contained inside another view.

UIButton

  • func setAttributedTitleString(_ title: String, for state: UIControl.State) - Replace the title of a button while keeping it’s attribute depending on its state.
  • func setBackgroundColor(color: UIColor, for state: UIControl.State) - Change the background color depending on the state.

UIViewController

  • func embed(child newChild: UIViewController, in container: UIView? = nil) - Embeds a child UIViewController.
  • func unembed() - Unembed as a child UIViewController of a parent UIViewController if it exists.
  • func unembedAllChildren() - Unembeds all children UIViewController.
  • func showModally(in viewController: UIViewController? = nil, completion: (() -> Void)? = nil) - Presents UIViewController into the navigationController view stack or on the UIViewController.topMost()
  • static func topMost(atRoot root: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? - Returns the top most view controller.
  • close(animated: Bool, completion: (() -> Void)? = nil) - Either dismisses or pops the view controller with a completion handler.

UINavigationController

  • func pushViewController(_ viewController: UIViewController, animated: Bool, completion: (() -> Void)?) - Pushes a view controller onto the receiver’s stack and updates the display with a completion handler.
  • func popViewController(animated: Bool, completion: (() -> Void)?) - Pops the top view controller from the navigation stack and updates the display with a completion handler.

UIWindow

  • convenience init(rootViewController: UIViewController) - Initializer assigning the window frame with the UIScreen bounds and the root view controller UIViewController.

Bundle

  • static var CheetahDigitalUIIdentifier: String - Property that returns the unique identifier of the CheetahDigitalUI.
  • static var CheetahDigitalUI: Bundle? - Returns the bundle of the CheetahDigitalUI.
  • static var cheetahBundles: [Bundle] - Returns all Cheetah Digital bundles/frameworks.
  • static func bundle(forResource resource: String?, withExtension resourceExtension: String?) -> Bundle? - Finds the bundle that contains the specified resource. This will first search for the resource in the main bundle and if it is not found, it will continue to search in the other Cheetah Digital bundles/frameworks.
  • static func bundle(forFileName fileName: String) -> Bundle? - Finds the bundle that contains the specified file name. This will first search for the resource in the main bundle and if it is not found, it will continue to search in the other Cheetah Digital bundles/frameworks.

UICollectionViewCell

  • class func nibName() -> String - Returns the nib name based on the class name as a String.
  • class func nib() -> UINib - Returns the nib based on the values returned by UICollectionViewCell.nibName() and Bundle.bundle(forFileName:).

String

  • var youtubeId: String? - Returns the first extracted YouTube Id from the String. If there is none, this will be nil.
  • var firstUrl: URL? - Returns the first URL found in the String. If there is none or the URL is invalid, this returns nil.
  • var attributedHTMLString: NSAttributedString? - Returns an NSAttributedString interpreting the HTML from the String`.
  • var strippedCSS: String - Returns the String stripped of CSS.
  • var strippedHTML: String - Returns the String stripped of HTML, CSS and NBSP.
  • var isValidURL: Bool - Returns true if the String is a valid URL along with scheme and host, otherwise it returns false.
  • var isValidEmail: Bool - Returns true if the String is a valid email address, otherwise it returns false.
  • var isValidPhoneNumber: Bool - Returns true if the String is a valid phone number, otherwise it returns false.
  • var isBlank: Bool - Returns true if the String is blank, otherwise it returns false.
  • func firstMatchForRegEx(_ pattern: String) -> String? - Finds the first match given a regular expression pattern in the String.
  • static func createPeriod(startDate: String, endDate: String, withFormat format: String = Date.CheetahStringFormat ) -> String - Create a string period based on the given date strings

Array

  • func appending(_ newElement: Element) -> [Element] - Returns an Array adding the a new element at the end.
  • func removing(at index: Int) -> [Element] - Returns the Array removing the element at the specified index.
  • mutating func move(at index: Index, to newIndex: Index) - Moves an element at the specified index to the designated index.

Array where Element: Equatable

  • mutating func move(_ item: Element, to newIndex: Index) - Moves an element to the designated index.
  • mutating func moveToStart(item: Element) - Moves an element to the start index.
  • mutating func moveToEnd(item: Element) - Moves an element to the end index.

DispatchQueue

  • static func mainAsyncIfNeeded(execute work: @escaping @convention(block) () -> Void) - Schedules a block asynchronously for execution in the main queue if not currently in the main queue otherwise the block executes immediately.

DateFormatter

  • convenience init(format: String? = nil, timeZone: TimeZone? = .current, locale: Locale? = Locale(identifier: "en_US_POSIX")) - Convenience init that creates a DateFormatter object with the desired format, time zone, and locale

Date

  • static let CheetahDateFormat - Constant time stamp format
  • static let CheetahStringFormat - Constant date format
  • var timestampString: String - Instance method that creates the time stamp string from Date object using the Date.CheetahDateFormat format
  • static func dateFrom(string: String, withFormat format: String) -> Date - Static method that creates a Date object from a string with a given format
  • static func dateFrom(timestampString timestamp: String) -> Date? - Static method that creates a Date object from a time stamp string
  • static func dateFrom(formattedString string: String) -> Date? - Static method that creates a Date object from a formatted string with the Date.CheetahStringFormat format
  • func string(withFormat format: String, locale: Locale? = nil) -> String - Instance method that creates a formatted dates string using the default locale (en_US_POSIX) and a specified format
  • func localizedString(withFormat format: String) -> String - Instance method that creates a formatted date string from the current locale using a specified format
  • func formattedStringWithDate(showDate: Bool, showTime: Bool, timeZone: TimeZone = .current) - Instance method that creates a formatted string of the date using the specified format
  • func numberOfYears(fromDate date: Date) -> Int? - Instance method that calculates the number of years between a given date

UIImage

  • static func fromMainOrCheetah(named: String) -> UIImage? - Finds the image asset with a given name.

UIDevice

  • static var deviceNamesList: [String: String] - Returns the contents of iOSDeviceModelMapping.plist as [String: String] dictionary
  • static var name: String - Model info the the current device

Notification.Name

  • static let analyticsLogEvent - Notification name for analyticsLogEvent
  • static let analyticsLogScreen - Notification name for analyticsLogScreen
  • static let selectionButtonGroupStateChange - Notification name for selectionButtonGroupStateChange
  • static let languageChange - Notification name for languageChange

UIFont

  • static var largeTitle - Returns the font of the largeTitle Text Appearance of the Theme Manager.
  • static var title1 - Returns the font of the title1 Text Appearance of the Theme Manager.
  • static var title2 - Returns the font of the title2 Text Appearance of the Theme Manager.
  • static var title3 - Returns the font of the title3 Text Appearance of the Theme Manager.
  • static var headline - Returns the font of the headline Text Appearance of the Theme Manager.
  • static var subheadline - Returns the font of the subheadline Text Appearance of the Theme Manager.
  • static var body - Returns the font of the body Text Appearance of the Theme Manager.
  • static var callout - Returns the font of the callout Text Appearance of the Theme Manager.
  • static var footnote - Returns the font of the footnote Text Appearance of the Theme Manager.
  • static var caption1 - Returns the font of the caption1 Text Appearance of the Theme Manager.
  • static var caption2 - Returns the font of the caption2 Text Appearance of the Theme Manager.