String

struct String
  • Gets the length of a string! Property only here for convenience

    Declaration

    Swift

    public var length: Int
  • Tells if the string is composed of only alphanumeric characters

    Declaration

    Swift

    public var isAlphaNumeric: Bool
  • Tells if the string is composed of digits only

    Declaration

    Swift

    public var digitsOnly: Bool
  • Tells if the string is composed of letters only

    Declaration

    Swift

    public var lettersOnly: Bool
  • Tells if the string contains only whitespaces and newlines

    Declaration

    Swift

    public var isBlank: Bool
  • Trims a string from leading and trailing whitespaces and optionally newline characters

    Parameter

    Parameter newLine: if true, will trim newline characters as well. Defaults to false.

    Returns

    a trimmed String

    Declaration

    Swift

    public func trim(shouldTrimNewLineCharacters newLine: Bool = false) -> String

    Parameters

    newLine

    if true, will trim newline characters as well. Defaults to false.

    Return Value

    a trimmed String

  • Converts a String to Bool

    Lowercased "true" will return true. Everything else is false

    Returns

    Bool

    Declaration

    Swift

    public func toBool() -> Bool

    Return Value

    Bool

  • Turns a String into a Date

    Parameter

    Parameter format: the input format of the string. For example, 20161129 is StringDateFormat.YYYYMMDD

    Returns

    a Date

    Declaration

    Swift

    public func toDate(stringDateFormat format: StringDateFormat = StringDateFormat.yyyyMMdd) -> Date?

    Parameters

    format

    the input format of the string. For example, “20161129” is StringDateFormat.YYYYMMDD

    Return Value

    a Date

  • Gets a substring from a string using a range. Function taken from http://stackoverflow.com/a/39509186/1296610

    Parameter

    Parameter range: The non inclusive range in the String object. For example, 0..<5

    Returns

    a substring as String

    Declaration

    Swift

    public func substring(_ range: Range<Int>) -> String

    Parameters

    range

    The non inclusive range in the String object. For example, 0..<5

    Return Value

    a substring as String