<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFMutableAttributedString",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@T@CFMutableAttributedStringRef"
  },
  "title" : "CFMutableAttributedString"
}
-->

# CFMutableAttributedString

```
class CFMutableAttributedString
```

## Overview

Instances of CFMutableAttributedString manage mutable character strings and associated sets of attributes (for example, font and kerning information) that apply to individual characters or ranges of characters in the string. CFAttributedString as defined in CoreFoundation provides the basic container functionality, while higher levels provide definitions for standard attributes, their values, and additional behaviors involving these. CFMutableAttributedString represents a mutable string—use CFAttributedString to create and manage an attributed string that cannot be changed after it has been created.

CFMutableAttributedString is not a “subclass” of CFMutableString; that is, it does not respond to CFMutableString (or CFString) function calls. CFAttributedString conceptually contains a CFMutableString to which it applies attributes. This protects you from ambiguities caused by the semantic differences between simple and attributed string. Functions defined for CFAttributedString can be applied to a CFMutableAttributedString object.

Attributes are identified by key/value pairs stored in CFDictionary objects. Keys must be CFString objects, while the corresponding values are CFType objects of an appropriate type. See the attribute constants in NSAttributedString Application Kit Additions Reference for standard attribute names in macOS and NSAttributedString UIKit Additions Reference on iOS.

> Important:
> Attribute dictionaries set for an attributed string must always be created with kCFCopyStringDictionaryKeyCallbacks for their dictionary key callbacks and kCFTypeDictionaryValueCallBacks for their value callbacks; otherwise it’s an error.

When you modify the contents of a mutable attributed string, it may have to do a lot of work to ensure it is internally consistent, and to coalesce runs of identical attributes. You can call [`CFAttributedStringBeginEditing(_:)`](/documentation/CoreFoundation/CFAttributedStringBeginEditing(_:)) and [`CFAttributedStringEndEditing(_:)`](/documentation/CoreFoundation/CFAttributedStringEndEditing(_:)) around a set of related mutation calls that don’t require the string to be in consistent state in between, and thereby reduce the amount of work necessary. These calls can be nested.

CFMutableAttributedString is “toll-free bridged” with its Foundation counterpart, NSMutableAttributedString. This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. Therefore, in a method where you see an `NSMutableAttributedString *` parameter, you can pass in an object of type `CFMutableAttributedStringRef`, and in a function where you see a `CFMutableAttributedStringRef` parameter, you can pass in an `NSMutableAttributedString` instance. See [Toll-Free Bridged Types](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFDesignConcepts/Articles/tollFreeBridgedTypes.html#//apple_ref/doc/uid/TP40010677) for more information on toll-free bridging.

There is not always a 1:1 mapping between `NSMutableAttributedString`‘s methods and CFMutableAttributedString’s functions. For example, to perform an operation equivalent to `NSMutableAttributedString`’s <doc://com.apple.documentation/documentation/Foundation/NSMutableAttributedString/append(_:)> method on a CFMutableAttributedString object, you can use [`CFAttributedStringReplaceAttributedString(_:_:_:)`](/documentation/CoreFoundation/CFAttributedStringReplaceAttributedString(_:_:_:)) and specify `CFRangeMake(CFAttributedStringGetLength(attrStr), 0)` as the range. Alternatively you can cast the CFMutableAttributedString object to an `NSMutableAttributedString` object and send the `appendAttributedString:` message.

## Topics

### Creating a CFMutableAttributedString

[`CFAttributedStringCreateMutable(_:_:)`](/documentation/CoreFoundation/CFAttributedStringCreateMutable(_:_:))

Creates a mutable attributed string.

[`CFAttributedStringCreateMutableCopy(_:_:_:)`](/documentation/CoreFoundation/CFAttributedStringCreateMutableCopy(_:_:_:))

Creates a mutable copy of an attributed string.

### Modifying a CFMutableAttributedString

[`CFAttributedStringBeginEditing(_:)`](/documentation/CoreFoundation/CFAttributedStringBeginEditing(_:))

Defers internal consistency-checking and coalescing for a mutable attributed string.

[`CFAttributedStringEndEditing(_:)`](/documentation/CoreFoundation/CFAttributedStringEndEditing(_:))

Re-enables internal consistency-checking and coalescing for a mutable attributed string.

[`CFAttributedStringGetMutableString(_:)`](/documentation/CoreFoundation/CFAttributedStringGetMutableString(_:))

Gets as a mutable string the string for an attributed string.

[`CFAttributedStringRemoveAttribute(_:_:_:)`](/documentation/CoreFoundation/CFAttributedStringRemoveAttribute(_:_:_:))

Removes the value of a single attribute over a specified range.

[`CFAttributedStringReplaceString(_:_:_:)`](/documentation/CoreFoundation/CFAttributedStringReplaceString(_:_:_:))

Modifies the string of an attributed string.

[`CFAttributedStringReplaceAttributedString(_:_:_:)`](/documentation/CoreFoundation/CFAttributedStringReplaceAttributedString(_:_:_:))

Replaces the attributed substring over a range with another attributed string.

[`CFAttributedStringSetAttribute(_:_:_:_:)`](/documentation/CoreFoundation/CFAttributedStringSetAttribute(_:_:_:_:))

Sets the value of a single attribute over the specified range.

[`CFAttributedStringSetAttributes(_:_:_:_:)`](/documentation/CoreFoundation/CFAttributedStringSetAttributes(_:_:_:_:))

Sets the value of attributes of a mutable attributed string over a specified range.

## See Also

  [Property List Programming Topics for Core Foundation](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFPropertyLists/CFPropertyLists.html#//apple_ref/doc/uid/10000130i)

  [String Programming Guide for Core Foundation](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFStrings/introCFStrings.html#//apple_ref/doc/uid/10000131i)

  [Data Formatting Guide for Core Foundation](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFDataFormatting/Articles/CFDataFormatting.html#//apple_ref/doc/uid/10000176i)



---

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)