<!--
{
  "availability" : [
    "iOS: 3.2.0 -",
    "iPadOS: 3.2.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSMutableAttributedString",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMutableAttributedString"
  },
  "title" : "NSMutableAttributedString"
}
-->

# NSMutableAttributedString

A mutable string with associated attributes (such as visual style, hyperlinks, or accessibility data) for portions of its text.

```
class NSMutableAttributedString
```

## Overview

The `NSMutableAttributedString` 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 [`NSAttributedString`](/documentation/Foundation/NSAttributedString) for more information about attributed strings.

`NSMutableAttributedString` adds two primitive methods to those of `NSAttributedString`. These primitive methods provide the basis for all the other methods in its class. The primitive [`replaceCharacters(in:with:)`](/documentation/Foundation/NSMutableAttributedString/replaceCharacters(in:with:)-6oq9r) method replaces a range of characters with those from a string, leaving all attribute information outside that range intact. The primitive [`setAttributes(_:range:)`](/documentation/Foundation/NSMutableAttributedString/setAttributes(_:range:)) method sets attributes and values for a given range of characters, replacing any previous attributes and values for that range.

In macOS, AppKit also uses <doc://com.apple.documentation/documentation/AppKit/NSParagraphStyle> and its subclass <doc://com.apple.documentation/documentation/AppKit/NSMutableParagraphStyle> to encapsulate the paragraph or ruler attributes used by the `NSAttributedString` classes.

Note that the default font for `NSAttributedString` 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, [`init(string:attributes:)`](/documentation/Foundation/NSAttributedString/init(string:attributes:)).

> iOS Note:
> In iOS, this class is used primarily in conjunction with the Core Text framework.

`NSMutableAttributedString` is “toll-free bridged” with its Core Foundation counterpart, <doc://com.apple.documentation/documentation/CoreFoundation/CFMutableAttributedString>. See [Toll-Free Bridging](https://developer.apple.com/library/archive/documentation/General/Conceptual/CocoaEncyclopedia/Toll-FreeBridgin/Toll-FreeBridgin.html#//apple_ref/doc/uid/TP40010810-CH2) for more information.

## Topics

### Retrieving Character Information

[`mutableString`](/documentation/Foundation/NSMutableAttributedString/mutableString)

The character contents of the receiver as a mutable string object.

### Changing Characters

[`replaceCharacters(in:with:)`](/documentation/Foundation/NSMutableAttributedString/replaceCharacters(in:with:)-6oq9r)

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

[`deleteCharacters(in:)`](/documentation/Foundation/NSMutableAttributedString/deleteCharacters(in:))

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

### Changing Attributes

[`setAttributes(_:range:)`](/documentation/Foundation/NSMutableAttributedString/setAttributes(_:range:))

Sets the attributes for the characters in the specified range to the specified attributes.

[`addAttribute(_:value:range:)`](/documentation/Foundation/NSMutableAttributedString/addAttribute(_:value:range:))

Adds an attribute with the given name and value to the characters in the specified range.

[`addAttributes(_:range:)`](/documentation/Foundation/NSMutableAttributedString/addAttributes(_:range:))

Adds the given collection of attributes to the characters in the specified range.

[`removeAttribute(_:range:)`](/documentation/Foundation/NSMutableAttributedString/removeAttribute(_:range:))

Removes the named attribute from the characters in the specified range.

[`applyFontTraits(_:range:)`](/documentation/Foundation/NSMutableAttributedString/applyFontTraits(_:range:))

Applies the specified font-related attributes to characters in the string.

[`setAlignment(_:range:)`](/documentation/Foundation/NSMutableAttributedString/setAlignment(_:range:))

Sets the alignment characteristic of the paragraph style attribute for the specified range of text.

[`setBaseWritingDirection(_:range:)`](/documentation/Foundation/NSMutableAttributedString/setBaseWritingDirection(_:range:))

Sets the base writing direction for the characters to the specified direction.

[`subscriptRange(_:)`](/documentation/Foundation/NSMutableAttributedString/subscriptRange(_:))

Decrements the value of the superscript attribute for characters in the specified range by one.

[`superscriptRange(_:)`](/documentation/Foundation/NSMutableAttributedString/superscriptRange(_:))

Increments the value of the superscript attribute for characters in the specified range by one.

[`unscriptRange(_:)`](/documentation/Foundation/NSMutableAttributedString/unscriptRange(_:))

Removes the superscript attribute from the characters in the specified range.

### Changing Characters and Attributes

[`append(_:)`](/documentation/Foundation/NSMutableAttributedString/append(_:))

Adds the characters and attributes of a given attributed string to the end of the receiver.

[`appendLocalizedFormat:`](/documentation/Foundation/NSMutableAttributedString/appendLocalizedFormat:)

Formats the specified string and arguments with the current locale,
then appends the result to the receiver.

[`insert(_:at:)`](/documentation/Foundation/NSMutableAttributedString/insert(_:at:))

Inserts the characters and attributes of the given attributed string into the receiver at the given index.

[`replaceCharacters(in:with:)`](/documentation/Foundation/NSMutableAttributedString/replaceCharacters(in:with:)-1uaw7)

Replaces the characters and attributes in a given range with the characters and attributes of the given attributed string.

[`setAttributedString(_:)`](/documentation/Foundation/NSMutableAttributedString/setAttributedString(_:))

Replaces the receiver’s entire contents with the characters and attributes of the given attributed string.

### Grouping Changes

[`beginEditing()`](/documentation/Foundation/NSMutableAttributedString/beginEditing())

Begins the buffering of changes to the string’s characters and attributes.

[`endEditing()`](/documentation/Foundation/NSMutableAttributedString/endEditing())

Ends the buffering of changes to the string’s characters and attributes.

### Updating Attachment Contents

[`updateAttachments(fromPath:)`](/documentation/Foundation/NSMutableAttributedString/updateAttachments(fromPath:))

Updates all attachments based on files contained in the RTFD file package at the specified file path.

### Fixing Attributes After Changes

[`fixAttributes(in:)`](/documentation/Foundation/NSMutableAttributedString/fixAttributes(in:))

Cleans up font, paragraph style, and attachment attributes within the given range.

[`fixAttachmentAttribute(in:)`](/documentation/Foundation/NSMutableAttributedString/fixAttachmentAttribute(in:))

Cleans up attachment attributes in the specified range and removes all attachment attributes assigned to characters except the designated attachment character.

[`fixFontAttribute(in:)`](/documentation/Foundation/NSMutableAttributedString/fixFontAttribute(in:))

Fixes the font attribute in the specified range and assigns default fonts where appropriate.

[`fixParagraphStyleAttribute(in:)`](/documentation/Foundation/NSMutableAttributedString/fixParagraphStyleAttribute(in:))

Fixes the paragraph style attributes in the specified range and assigns a paragraph style to all characters in the paragraph.

### Reading Content

[`read(from:options:documentAttributes:)`](/documentation/Foundation/NSMutableAttributedString/read(from:options:documentAttributes:)-5mbcx)

Sets the contents of the attributed string using the specified data object`.`

[`read(from:options:documentAttributes:)`](/documentation/Foundation/NSMutableAttributedString/read(from:options:documentAttributes:)-54wth)

Sets the contents of attributed string using the contents of the specified file.

### Deprecated

[`read(from:options:documentAttributes:)`](/documentation/Foundation/NSMutableAttributedString/read(from:options:documentAttributes:)-967j7)

Sets the contents of the receiver from the specified data object`.`

[`read(from:options:documentAttributes:)`](/documentation/Foundation/NSMutableAttributedString/read(from:options:documentAttributes:)-85y1d)

Sets the contents of receiver from the file at the specified URL.

[`read(fromFileURL:options:documentAttributes:)`](/documentation/Foundation/NSMutableAttributedString/read(fromFileURL:options:documentAttributes:))

Sets the contents of the receiver from the file at the given URL.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)