Contents

OSLogInt32ExtendedFormat.truth

A format that displays a 32-bit integer as true or false.

Declaration

case truth

Discussion

Use this option to format the interpolated value as either true or false. The formatter converts all positive and negative nonzero values to true, and only zero to false. The following example applies the truth formatter to the 32-bit integer value 0:

// Create a logger with the specified subsystem and category.
let logger = Logger(subsystem: "com.example.OSLogValueFormatting",
                    category: "Formatter Output")
                
// Assign the value to interpolate.
let value: Int32 = 0
                
// Write the value to the log using the specified format.
logger.info(".truth output is \(value, format: .truth)")

And the system writes the following message to the log:

[Formatter Output] .truth output is false

See Also

Getting the Formats