Returns the trailing whitespace width for a line.


func CTLineGetTrailingWhitespaceWidth(_ line: CTLine) -> Double



The line whose trailing whitespace width is calculated.

Return Value

The width of the line's trailing whitespace. If the line is invalid, this function will always return zero.


Creating a line for a width can result in a line that is actually longer than the desired width due to trailing whitespace. Although this is typically not an issue due to whitespace being invisible, this function can be used to determine what amount of a line's width is due to trailing whitespace.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software