Character

struct Character
  • SwifterSwift: Check if character is emoji.

       Character("😀").isEmoji -> true
    

    Declaration

    Swift

    var isEmoji: Bool { get }
  • SwifterSwift: Check if character is number.

       Character("1").isNumber -> true
       Character("a").isNumber -> false
    

    Declaration

    Swift

    var isNumber: Bool { get }
  • SwifterSwift: Check if character is a letter.

       Character("4").isLetter -> false
       Character("a").isLetter -> true
    

    Declaration

    Swift

    var isLetter: Bool { get }
  • SwifterSwift: Check if character is lowercased.

       Character("a").isLowercased -> true
       Character("A").isLowercased -> false
    

    Declaration

    Swift

    var isLowercased: Bool { get }
  • SwifterSwift: Check if character is uppercased.

       Character("a").isUppercased -> false
       Character("A").isUppercased -> true
    

    Declaration

    Swift

    var isUppercased: Bool { get }
  • SwifterSwift: Check if character is white space.

       Character(" ").isWhiteSpace -> true
       Character("A").isWhiteSpace -> false
    

    Declaration

    Swift

    var isWhiteSpace: Bool { get }
  • int

    SwifterSwift: Integer from character (if applicable).

       Character("1").int -> 1
       Character("A").int -> nil
    

    Declaration

    Swift

    var int: Int? { get }
  • SwifterSwift: String from character.

       Character("a").string -> "a"
    

    Declaration

    Swift

    var string: String { get }
  • SwifterSwift: Return the character lowercased.

       Character("A").lowercased -> Character("a")
    

    Declaration

    Swift

    var lowercased: Character { get }
  • SwifterSwift: Return the character uppercased.

       Character("a").uppercased -> Character("A")
    

    Declaration

    Swift

    var uppercased: Character { get }
  • SwifterSwift: Random character.

    Character.random() -> k

    Declaration

    Swift

    static func randomAlphanumeric() -> Character

    Return Value

    A random character.

  • SwifterSwift: Repeat character multiple times.

       Character("-") * 10 -> "----------"
    

    Declaration

    Swift

    static func * (lhs: Character, rhs: Int) -> String

    Parameters

    lhs

    character to repeat.

    rhs

    number of times to repeat character.

    Return Value

    string with character repeated n times.

  • SwifterSwift: Repeat character multiple times.

       10 * Character("-") -> "----------"
    

    Declaration

    Swift

    static func * (lhs: Int, rhs: Character) -> String

    Parameters

    lhs

    number of times to repeat character.

    rhs

    character to repeat.

    Return Value

    string with character repeated n times.