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

# CFAttributedString

```
class CFAttributedString
```

## Overview

Instances of CFAttributedString manage 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 Core Foundation provides the basic container functionality, while higher levels provide definitions for standard attributes, their values, and additional behaviors involving these. CFAttributedString represents an immutable string—use [`CFMutableAttributedString`](/documentation/CoreFoundation/CFMutableAttributedString) to create and manage an attributed string that can be changed after it has been created.

CFAttributedString is not a “subclass” of CFString; that is, it does not respond to CFString function calls. CFAttributedString conceptually contains a CFString to which it applies attributes. This protects you from ambiguities caused by the semantic differences between simple and attributed string.

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 or NSAttributedString UIKit Additions Reference for standard attribute names.

> Important:
> Attribute dictionaries set for an attributed string must always be created with ``doc://com.apple.corefoundation/documentation/CoreFoundation/kCFCopyStringDictionaryKeyCallBacks`` for their dictionary key callbacks and ``doc://com.apple.corefoundation/documentation/CoreFoundation/kCFTypeDictionaryValueCallBacks`` for their value callbacks; otherwise it’s an error.

CFAttributedString is “toll-free bridged” with its Foundation counterpart, <doc://com.apple.documentation/documentation/Foundation/NSAttributedString>. 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 `NSAttributedString *` parameter, you can pass in a `CFAttributedStringRef`, and in a function where you see a `CFAttributedStringRef` parameter, you can pass in an <doc://com.apple.documentation/documentation/Foundation/NSAttributedString> instance. This also applies to concrete subclasses of <doc://com.apple.documentation/documentation/Foundation/NSAttributedString>. 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.

## Topics

### Creating a CFAttributedString

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

Creates an attributed string with specified string and attributes.

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

Creates an immutable copy of an attributed string.

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

Creates a sub-attributed string from the specified range.

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

Returns the length of the attributed string in characters.

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

Returns the string for an attributed string.

### Accessing Attributes

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

Returns the value of a given attribute of an attributed string at a specified location.

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

Returns the attributes of an attributed string at a specified location.

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

Returns the value of a given attribute of an attributed string at a specified location.

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

Returns the attributes of an attributed string at a specified location.

### Getting Attributed String Properties

[`CFAttributedStringGetTypeID()`](/documentation/CoreFoundation/CFAttributedStringGetTypeID())

Returns the type identifier for the CFAttributedString opaque type.

## 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)