String

extension String: RawRepresentable
extension String: PathAppendable
  • Declaration

    Swift

    public init?(rawValue: String)
  • Declaration

    Swift

    public var rawValue: String { get }
  • Returns a localized representation of the string.

    Seealso

    `NSLocalizedString.

    Declaration

    Swift

    func localized(withArguments arguments: CVarArg..., bundle: Bundle = Bundle.main) -> String

    Parameters

    bundle

    Bundle were to search for localization.

    arguments

    Formatting arguments.

  • Returns a the formatted string.

    Seealso

    String.init(format:arguments:).

    Declaration

    Swift

    func format(with arguments: CVarArg...) -> String

    Parameters

    arguments

    Formatting arguments.

  • Returns an NSAttributedString with the same content as self but with the attributes specified for each first appearance of substrings passed.

    Seealso

    NSMutableAttributedString.addAttributes(_:range:)

    Declaration

    Swift

    func format(withAttributes attrs: [String : [NSAttributedString.Key : Any]]) -> NSAttributedString

    Parameters

    attributes

    A dictionary that specifies the attributes to add to the substring specified. The attributes should be specified with a dictionary itself in the same format required by the NSAttributedString. The possible keys are specified in NSAttributedString.h (like NSFontAttributeName).

  • url

    Builds an NSURL from a string.

    Declaration

    Swift

    var url: URL? { get }
  • Checks if the string has spaces or not.

    Declaration

    Swift

    var hasSpaces: Bool { get }
  • Checks if a string is a valid email or not.

    Declaration

    Swift

    func isValidEmail() -> Bool
  • Returns a copy of the string without its leading and trailing whitespace and newlines.

    Declaration

    Swift

    var trimmed: String { get }
  • Returns a new string in which all occurrences of a target string in a specified range of the String are replaced by another given string.

    Seealso

    stringByReplacingOccurrencesOfString().

    Declaration

    Swift

    func replacing(_ target: String, with replacement: String, options: NSString.CompareOptions = .literal, range: Range<Index>? = .none) -> String

    Parameters

    target

    The string to replace.

    with

    The replacement.

    options

    The comparing options. Default: LiteralSearch

    range

    The range of the string to search.

  • Returns a new string without whitespaces.

    Declaration

    Swift

    var withoutWhiteSpaces: String { get }
  • Returns true if the string is not empty, false if not.

    Declaration

    Swift

    var isNotEmpty: Bool { get }
  • Returns a new string that contains the same as self except for the given suffix. If it doesn’t have the suffix, it returns the same as self. If it has the suffix more than one time, it just removes the last occurence of it.

    The comparison is both case sensitive and Unicode safe.

    Seealso

    hasSuffix.

    Declaration

    Swift

    func remove(suffix: String) -> String
  • Returns a new string that contains the same as self except for the given prefix. If it doesn’t have the prefix, it returns the same as self. If it has the prefix more than one time, it just removes the first occurence of it.

    The comparison is both case sensitive and Unicode safe.

    Seealso

    hasPrefix.

    Declaration

    Swift

    func remove(prefix: String) -> String
  • Returns UIImage drawing of the string, it’s recomended for using emojis as images, but it can be used with any string.

    Declaration

    Swift

    func toImage(fontSize: CGFloat) -> UIImage?

    Parameters

    fontSize

    CGFloat, size of the font to use on the represented string.

  • Returns UIImage drawing of the string, it’s recomended for using emojis as images, but it can be used with any string.

    Declaration

    Swift

    func toImage(font: UIFont) -> UIImage?

    Parameters

    font

    UIFont to apply to the drawn string.

  • Repeats a string multiple times.

    Declaration

    Swift

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

    Parameters

    lhs

    string to repeat.

    rhs

    number of times to repeat string.

  • Repeats a string multiple times.

    Declaration

    Swift

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

    Parameters

    lhs

    number of times to repeat string.

    rhs

    string to repeat.