Cheetah CES Docs Portal

Navigation
Home
GitHub
Email
Corporate Site


Cheetah Digital Utils Kit

« Back to iOS Kit References

This kit contains the following extensions:

  • Array
  • Bundle
  • Data
  • Date
  • DateFormatter
  • Dictionary
  • Encodable
  • JSONDecoder
  • KeyedDecodingContainer
  • Localizer
  • Notification
  • Result
  • String
  • UIDevice
  • UIImage

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

The Cheetah Digital Utils iOS SDK contains a collection of classes, methods, and protocols that are generally used across all other Cheetah Digital iOS SDKs.

Array:

  • appending(_:)
    • Returns an Array adding the a new element at the end.
  • removing(at:)
    • Returns the Array removing the element at the specified index.
  • move(at:to:)
    • Moves an element at the specified index to the designated index.
  • subscript(safe:)
    • Returns the element at the specified index if it is within bounds, otherwise nil.
Available where Element: Equatable
  • move(_:to:)
    • Moves an element to the designated index.
  • moveToStart(item:)
    • Moves an element to the start index.
  • moveToEnd(item:)
    • Moves an element to the end index.

Bundle:

  • CheetahDigitalUtilsIdentifier
    • Property that returns the unique identifier of the CheetahDigitalUtils.
  • cheetahBundles
    • Returns all Cheetah Loyalty bundles/frameworks.
  • testBundle
    • Returns the very first test bundle found if any.
  • bundle(forResource:withExtension:)
    • Finds the bundle that contains the specified resource.
  • bundle(forFileName:)
    • Finds the bundle that contains the specified file name.

Data:

  • hexString
    • Returns a hex encoded string representation of the data object.
  • serializedJsonObject(options:)
    • Returns a Foundation object from the JSON data.

Date:

  • dateFrom(string:withFormat:)
    • Static method that creates a Date object from a string with a given format
  • string(withFormat:locale:)
    • Instance method that creates a formatted dates string using the default locale (en_US_POSIX) and a specified format.
  • localizedString(withFormat:)
    • Instance method that creates a formatted date string from the current locale using a specified format.
  • formattedStringWithDate(showDate:showTime:timeZone:)
    • Instance method that creates a formatted string of the date using the specified format.
  • numberOfYears(fromDate:)
    • Instance method that calculates the number of years between a given date.

DateFormatter:

  • init(format:timeZone:locale:)
    • Convenience init that creates a DateFormatter object with the desired format, time zone, and locale.

Dictionary:

Available where Key == String, Value == Any

  • filterVoid()
    • Returns a new dictionary removing the key-value pairs of the dictionary that have an empty or null value.

Encodable:

  • json
    • Returns a JSON serialized dictionary of the encodable object.

JSONDecoder:

  • decode(_:from:keyPath:)
    • Decodes a value of the given type for the given keypath from the JSON object.

KeyedDecodingContainer:

  • decode(forKey:defaultValue:)
    • Decodes a value of the given type for the given key if present and if not, returns the provided default value.

Notification:

  • init(_:object:userInfo:)
    • Initializes a newNotification using a CheetahNotification.

NotificationCenter:

  • addObserver(for:object:queue:using:)
    • Adds an entry to the notification center’s dispatch table for a CheetahNotification that includes the sender, a notification queue, and a block to add to the queue.

Result:

  • isSuccess
    • Returns true if the result is a success, false otherwise.
  • isFailure
    • Returns true if the result is a failure, false otherwise.
  • value
    • Returns the associated value if the result is a success, nil otherwise.
  • error
    • Returns the associated error value if the result is a failure, nil otherwise.
  • description
    • The textual representation used when written to an output stream, which includes whether the result was a success or failure.
  • debugDescription
    • The debug textual representation used when written to an output stream, which includes whether the result was a success or failure in addition to the value or error.

String:

  • localized
    • Retuns the localized string using the CheetahDigitalUtils.Localizer.
  • asURL()
    • Returns a URL if the String can be used to initialize a URL, otherwise throws if an error was encountered.
  • youtubeId
    • Returns the first extracted YouTube Id from the String. If there is none, this will be nil.
  • firstUrl
    • Returns the first URL found in the String. If there is none or the URL is invalid, this returns nil.
  • firstMatchForRegEx(_:)
    • Finds the first match given a regular expression pattern in the String.
  • attributedHTMLString
    • Returns an NSAttributedString interpreting the HTML from the String.
  • strippedCSS
    • Returns the String stripped of CSS.
  • strippedHTML
    • Returns the String stripped of HTML, CSS and NBSP.
  • isValidURL
    • Returns true if the String is a valid URL along with scheme and host, otherwise it returns false.
  • isValidEmail
    • Returns true if the String is a valid email address, otherwise it returns false.
  • isValidPhoneNumber
    • Returns true if the String is a valid phone number, otherwise it returns false.
  • isBlank
    • Returns true if the String is blank, otherwise it returns false. A blank string is considered either empty or just having whitespace or new lines
  • createPeriod(startDate:endDate:dateFormat:resultFormat:)
    • Create a string period based on the given date strings. If both parameters or the startDate are invalid, this method will just throw an empty string. But if endDate is invalid this will instead used the word Onwards.

UIDevice:

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

UIImage:

  • compressedImage(compressRatio:maxCompressRatio:)
    • Compress the instance of the image.
  • scaledDownImage(to:)
    • Redraw scaled down image respecting originally captured orientation settings.