Mac Developer Library

Developer

Foundation Framework Reference NSMutableAttributedString Class Reference

Options
Deployment Target:

On This Page
Language:

NSMutableAttributedString

NSMutableAttributedString declares the programmatic interface to objects that manage mutable attributed strings. You can add and remove characters (raw strings) and attributes separately or together as attributed strings. See the class description for NSAttributedString for more information about attributed strings. More...

Inheritance


Import Statement


import Foundation @import Foundation;

Availability


Available in OS X v10.0 and later.
  • The character contents of the receiver as an NSMutableString object.

    Declaration

    Swift

    var mutableString: NSMutableString { get }

    Objective-C

    @property(readonly, retain) NSMutableString *mutableString

    Discussion

    The receiver tracks changes to this string and keeps its attribute mappings up to date.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Replaces the characters in the given range with the characters of the given string.

    Declaration

    Swift

    func replaceCharactersInRange(_ aRange: NSRange, withString aString: String)

    Objective-C

    - (void)replaceCharactersInRange:(NSRange)aRange withString:(NSString *)aString

    Parameters

    aRange

    A range specifying the characters to replace.

    aString

    A string specifying the characters to replace those in aRange.

    Discussion

    The new characters inherit the attributes of the first replaced character from aRange. Where the length of aRange is 0, the new characters inherit the attributes of the character preceding aRange if it has any, otherwise of the character following aRange.

    Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Deletes the characters in the given range along with their associated attributes.

    Declaration

    Swift

    func deleteCharactersInRange(_ aRange: NSRange)

    Objective-C

    - (void)deleteCharactersInRange:(NSRange)aRange

    Parameters

    aRange

    A range specifying the characters to delete.

    Discussion

    Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Overridden by subclasses to buffer or optimize a series of changes to the receiver’s characters or attributes, until it receives a matching endEditing message, upon which it can consolidate changes and notify any observers that it has changed.

    Declaration

    Swift

    func beginEditing()

    Objective-C

    - (void)beginEditing

    Discussion

    You can nest pairs of beginEditing and endEditing messages.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Overridden by subclasses to consolidate changes made since a previous beginEditing message and to notify any observers of the changes.

    Declaration

    Swift

    func endEditing()

    Objective-C

    - (void)endEditing

    Discussion

    The NSMutableAttributedString implementation does nothing. NSTextStorage, for example, overrides this method to invoke fixAttributesInRange: and to inform its NSLayoutManager objects that they need to re-lay the text.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

    See Also

    – processEditing (NSTextStorage)