Attributed string objects manage character strings and associated sets of attributes (for example, font and kerning) that apply to individual characters or ranges of characters in the string. The classes
NSMutableAttributedString declare the programmatic interface for read-only attributed strings and modifiable attributed strings, respectively. The Foundation Kit defines the basic functionality, while additional Objective-C methods are defined in the Application Kit. The Application Kit also uses a subclass of
NSTextStorage, to provide the storage for the extended text-handling system (see Text System Storage Layer Overview).
NSMutableAttributedString are toll-free bridged to their Core Foundation counterparts, CFAttributedString and CFMutableAttributedString respectively. This means that a Foundation attributed string is interchangeable in function or method calls with the corresponding bridged Core Foundation type. Therefore, in a method where you see an
NSMutableAttributedString * parameter, you can pass in a variable of type
CFMutableAttributedStringRef, and in a function where you see a
CFAttributedStringRef parameter, you can pass in an instance of
NSAttributedString is not a subclass of
NSString. It contains an
NSString object to which it applies attributes. This protects users of attributed strings from ambiguities caused by the semantic differences between simple and attributed strings. For example, equality can’t be simply defined between an
NSString and an attributed string. The attributed string classes adopt the
NSMutableCopying protocols, making it convenient to convert an attributed string from one type to the other.
NSMutableAttributedString add a number of features to the basic content storage of
Association of arbitrary, programmer-defined attributes with ranges of characters.
Preservation of attribute-to-character mapping after changes (
Support for RTF, including file attachments and graphics.
Linguistic unit (word) and line calculation.
An attributed string identifies attributes by name, storing their values as opaque
ids in an
NSDictionary object. For example, the text font is stored as an
NSFont object under the name given by
NSFontAttributeName. You can associate any object value, by any name, with a given range of characters in the attributed string.
A mutable attributed string keeps track of the attribute mapping as characters are added to and deleted from it and as attributes are changed. It allows you to group batches of edits with the
endEditing methods, and to consolidate changes to the attribute-to-character mapping with the
© 1997, 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-10-19)