YMFormatter

public enum YMFormatter

A collection of methods for formatting different kinds of data, such as names, prices, and more.

Core Declaration

  • A collection of methods that allow formatting Dates as other types, mainly Strings.

    See more

    Declaration

    Swift

    public struct Date
  • A collection of methods that allow formatting numbers as other types, primarily Strings.

    See more

    Declaration

    Swift

    public struct Number

Person Name String

  • Compose person name components into a single string with the specified style.

    • Even though all parameters have default values, you should provide at least one name component; otherwise, an empty string will be returned.

    Declaration

    Swift

    public static func getPersonNameString(
        withStyle style: PersonNameComponentsFormatter.Style = .default,
        prefix: String? = nil,
        firstName: String? = nil,
        middleName: String? = nil,
        nickname: String? = nil,
        lastName: String? = nil,
        suffix: String? = nil
    ) -> String

    Parameters

    style

    Optional. See PersonNameComponentsFormatter.Style.

    prefix

    Optional. Dr., Mr., Ms., etc.

    firstName

    Optional. Johnatan

    middleName

    Optional. Maple

    nickname

    Optional. Johnny

    lastName

    Optional. Appleseed

    suffix

    Optional. Esq., Jr., Ph.D., etc.

  • Compose a person’s first name and last name into a single string with the specified style.

    • Although both firstName and lastName are optional, specify at least one of arguments; otherwise, an empty string will be returned.

    Declaration

    Swift

    public static func getPersonNameString(
        withStyle style: PersonNameComponentsFormatter.Style = .default,
        firstName: String? = nil,
        lastName: String? = nil
    ) -> String

    Parameters

    style

    Optional. See PersonNameComponentsFormatter.Style.

    firstName

    Optional. Johnatan

    lastName

    Optional. Appleseed

Price String

  • Converts NSNumber values to highly customizable price strings.

    • By default, this methods returns a price string with the locale-specified grouping separator and the number of fraction digits varying from 0 to 3, depending on the value.

    Declaration

    Swift

    public static func getPriceString(
        from inputValue: NSNumber,
        significantDigits: Bool = false,
        minSignificantDigits: Int? = nil,
        maxSignificantDigits: Int? = nil,
        fixedFractionDigits: Int? = nil,
        minFractionDigits: Int = 0,
        maxFractionDigits: Int = 3,
        groupingSeparatorIsEnabled: Bool = true,
        locale: Locale = .current,
        currencyCode: String? = nil,
        currencySymbol: String? = nil,
        configurationClosure: (NumberFormatter) -> Void = { _ in }
    ) -> String?

    Parameters

    inputValue

    Required. The value to convert to a price string.

    significantDigits

    Optional. Specifies whether to use “significant digits” (see NumberFormatter.usesSignificantDigits for details); default is false.

    minSignificantDigits

    Optional. The minimum number of significant digits to display; default is nil; if not set, uses NumberFormatter‘s default value (1).

    maxSignificantDigits

    Optional. The maximum number of significant digits to display; default is nil; if not set, uses NumberFormatter‘s default value (6).

    fixedFractionDigits

    Optional. Specifies whether to use the exact number of fraction digits; default is nil, which means the number of fraction digits will depend on values specified in minFractionDigits and maxFractionDigits.

    minFractionDigits

    Optional. The minimum number of fraction digits to display; default is 0.

    maxFractionDigits

    Optional. The maximum number of fraction digits to display; default is 3.

    groupingSeparatorIsEnabled

    Optional. Specifies whether to use a locale-specified grouping separator; default is true.

    locale

    Optional. The locale to use in the price string; default is .current.

    currencyCode

    Optional. An ISO 4217-compliant currency code (such as “USD” or “EUR”).

    currencySymbol

    Optional. A symbol that represents the currency (such as “$” or “€”).

    Return Value

    A string that represents the original NSNumber value with the specified style applied.