String

extension String
extension String: URLConvertible
  • Retuns the localized string using the CheetahDigitalUtils.Localizer.

    Declaration

    Swift

    public var localized: String { get }

URLConvertible

  • Returns a URL if the String can be used to initialize a URL, otherwise throws if an error was encountered.

    Throws

    A URLError.invalidURL error.

    Declaration

    Swift

    public func asURL() throws -> URL

    Return Value

    The URL initialized with the String.

  • Returns the first extracted YouTube Id from the String. If there is none, this will be nil.

    Declaration

    Swift

    var youtubeId: String? { get }
  • Returns the first URL found in the String. If there is none or the URL is invalid, this returns nil.

    Declaration

    Swift

    var firstUrl: URL? { get }
  • Finds the first match given a regular expression pattern in the String.

    Declaration

    Swift

    func firstMatchForRegEx(_ pattern: String) -> String?

    Parameters

    pattern

    The regular expression pattern.

    Return Value

    The first match given a regular expression pattern in the String. If there is none, this is nil.

  • Returns an NSAttributedString interpreting the HTML from the String.

    Declaration

    Swift

    var attributedHTMLString: NSAttributedString? { get }
  • Returns the String stripped of CSS.

    Declaration

    Swift

    var strippedCSS: String { get }
  • Returns the String stripped of HTML, CSS and NBSP.

    Declaration

    Swift

    var strippedHTML: String { get }
  • Returns true if the String is a valid URL along with scheme and host, otherwise it returns false.

    Declaration

    Swift

    var isValidURL: Bool { get }
  • Returns true if the String is a valid email address, otherwise it returns false.

    Declaration

    Swift

    var isValidEmail: Bool { get }
  • Returns true if the String is a valid phone number, otherwise it returns false.

    A valid phone number in this case is a String with no letters.

    Declaration

    Swift

    var isValidPhoneNumber: Bool { get }
  • 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.

    Declaration

    Swift

    var isBlank: Bool { get }
  • 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.

    Declaration

    Swift

    static func createPeriod(startDate: String,
                             endDate: String,
                             dateFormat: String,
                             resultFormat: String) -> String

    Parameters

    startDate

    The beginning of the period.

    endDate

    The end of the period.

    dateFormat

    The format of the given dates.

    resultFormat

    The resulting format of the dates in the period string.

    Return Value

    A string period.