One Logo Pool Ball
Foundation · IOS API REFERENCE

ByteCountFormatStyle

struct · iOS 15.0+ · SDK 27.1

struct ByteCountFormatStyle

A format style that provides string representations of byte counts. The following example creates an `Int` representing 1,024 bytes, and then formats it as an expression of memory storage, with the default byte count format style. ```swift let count: Int64 = 1024 let formatted = count.formatted(.byteCount(style: .memory)) // "1 kB" ``` You can also customize a byte count format style, and use this to format one or more `Int64` instances. The following example creates a format style to only use kilobyte units, and to spell out the exact byte count of the measurement. ```swift let style = ByteCountFormatStyle( style: .memory, allowedUnits: [.kb], spellsOutZero: true, includesActualByteCount: false, locale: Locale(identifier: "en_US")) let counts: [Int64] = [0, 1024, 2048, 4096, 8192, 16384, 32768, 65536] let formatted = counts.map { style.format($0) } // ["Zero kB", "1 kB", "2 kB", "4 kB", "8 kB", "16 kB", "32 kB", "64 kB"] ```

Members (15)

get · iOS 15.0+

includesActualByteCount

TypeScript
get includesActualByteCount(): boolean
Swift declaration
var includesActualByteCount: Bool { get set }

A Boolean value that indicates whether the format style should include the exact byte count, in addition to expressing it in terms of units.

set · iOS 15.0+

includesActualByteCount

TypeScript
set includesActualByteCount(value: boolean)
Swift declaration
var includesActualByteCount: Bool { get set }

A Boolean value that indicates whether the format style should include the exact byte count, in addition to expressing it in terms of units.

get · iOS 15.0+

attributed

TypeScript
get attributed(): ByteCountFormatStyle_Attributed
Swift declaration
var attributed: ByteCountFormatStyle.Attributed

An attributed format style based on the byte count format style.

set · iOS 15.0+

attributed

TypeScript
set attributed(value: ByteCountFormatStyle_Attributed)
Swift declaration
var attributed: ByteCountFormatStyle.Attributed

An attributed format style based on the byte count format style.

get · iOS 15.0+

allowedUnits

TypeScript
get allowedUnits(): ByteCountFormatStyle_Units
Swift declaration
var allowedUnits: ByteCountFormatStyle.Units { get set }

The units the format style can use to express the byte count.

set · iOS 15.0+

allowedUnits

TypeScript
set allowedUnits(value: ByteCountFormatStyle_Units)
Swift declaration
var allowedUnits: ByteCountFormatStyle.Units { get set }

The units the format style can use to express the byte count.

get · iOS 15.0+

spellsOutZero

TypeScript
get spellsOutZero(): boolean
Swift declaration
var spellsOutZero: Bool { get set }

A Boolean value that indicates whether the format style should spell out zero-byte values as text.

set · iOS 15.0+

spellsOutZero

TypeScript
set spellsOutZero(value: boolean)
Swift declaration
var spellsOutZero: Bool { get set }

A Boolean value that indicates whether the format style should spell out zero-byte values as text.

init · iOS 15.0+

init

TypeScript
static init(style?: ByteCountFormatStyle_Style, allowedUnits?: ByteCountFormatStyle_Units, spellsOutZero?: boolean, includesActualByteCount?: boolean, locale?: Locale): ByteCountFormatStyle
Swift declaration
init(style: ByteCountFormatStyle.Style = .file, allowedUnits: ByteCountFormatStyle.Units = .all, spellsOutZero: Bool = true, includesActualByteCount: Bool = false, locale: Locale = .autoupdatingCurrent)

Initializes a byte count format style.

get · iOS 15.0+

style

TypeScript
get style(): ByteCountFormatStyle_Style
Swift declaration
var style: ByteCountFormatStyle.Style { get set }

The semantic style the format style uses to represent a byte count value.

set · iOS 15.0+

style

TypeScript
set style(value: ByteCountFormatStyle_Style)
Swift declaration
var style: ByteCountFormatStyle.Style { get set }

The semantic style the format style uses to represent a byte count value.

method · iOS 15.0+

format

TypeScript
format(value: number): string
Swift declaration
func format(_ value: Int64) -> String

Formats a numeric byte count, using this style.

get · iOS 15.0+

locale

TypeScript
get locale(): Locale
Swift declaration
var locale: Locale { get set }

The locale to use to format the numeric part of the byte count.

set · iOS 15.0+

locale

TypeScript
set locale(value: Locale)
Swift declaration
var locale: Locale { get set }

The locale to use to format the numeric part of the byte count.

method · iOS 15.0+

locale

TypeScript
locale22027(locale: Locale): ByteCountFormatStyle
Swift declaration
func locale(_ locale: Locale) -> ByteCountFormatStyle

Modifies the format style to use the specified locale.

Skipped declarations

No declarations were skipped in this snapshot.

All Foundation types →