A mutable string object that also contains attributes (such as visual style, hyperlinks, or accessibility data) associated with various portions of its text content.
- iOS 3.2+
- macOS 10.0+
- UIKit for Mac 13.0+Beta
- tvOS 9.0+
- watchOS 2.0+
NSMutable class declares additional methods for mutating the content of an attributed string. You can add and remove characters (raw strings) and attributes separately or together as attributed strings. See the class description for
NSAttributed for more information about attributed strings.
NSMutable adds two primitive methods to those of
NSAttributed. These primitive methods provide the basis for all the other methods in its class. The primitive
replace method replaces a range of characters with those from a string, leaving all attribute information outside that range intact. The primitive
set method sets attributes and values for a given range of characters, replacing any previous attributes and values for that range.
Note that the default font for
NSAttributed objects is Helvetica 12-point, which may differ from the macOS system font, so you may wish to create the string with non-default attributes suitable for your application using, for example,