< Previous PageNext Page > Hide TOC

Formatters

Formatters define a common interface for creating, interpreting, and validating the textual representation of objects. The Foundation framework provides two concrete subclasses of NSFormatter to generate these objects: NSNumberFormatter and NSDateFormatter. The Core Foundation provides two equivalent opaque types: CFNumberFormatter and CFDateFormatter. The formatter objects in Foundation and Core Foundation are similar but are not toll-free bridged.

In Cocoa, user interface cells that display text but have an arbitrary object as their content can use formatters for both input and output. When cells are displayed, the cells convert arbitrary object to a textual representation. How a cell displays the object depends on whether or not the cell has an associated formatter. If a cell has no formatter, the cell displays its content by using the localized representation of the object. If the cell has a formatter, the cell obtains a formatted string from the formatter. When the user enters text into a cell, the cell converts the text to the underlying object using its formatter.

In Carbon, you primarily use formatters to create formatted strings and parse them programmatically.



< Previous PageNext Page > Hide TOC


© 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-10-15)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.