<!--
{
  "documentType" : "article",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/creation-methods",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Creation methods"
}
-->

# Creation methods

Create attributed strings from existing content or raw text and apply the initial attributes.

## Topics

### Creating from another string

[`init(string: String)`](/documentation/Foundation/NSAttributedString/init(string:))

Creates an attributed string with the specified text and no attribute information.

[`init(string: String, attributes: [NSAttributedString.Key : Any]?)`](/documentation/Foundation/NSAttributedString/init(string:attributes:))

Creates an attributed string with the specified text and attributes.

[`init(attributedString: NSAttributedString)`](/documentation/Foundation/NSAttributedString/init(attributedString:))

Creates a new attributed string from the contents of another attributed string.

### Creating from a Swift attributed string

### Creating a formatted string

[`convenience init(AttributedString)`](/documentation/Foundation/NSAttributedString/init(_:))

Creates a reference-type attributed string from the specified value-type attributed string.

[`convenience init<S>(AttributedString, including: S.Type) throws`](/documentation/Foundation/NSAttributedString/init(_:including:)-9gogq)

Creates a reference-type attributed string from the specified value-type attributed string, including an attribute scope.

[`convenience init<S>(AttributedString, including: KeyPath<AttributeScopes, S.Type>) throws`](/documentation/Foundation/NSAttributedString/init(_:including:)-8iy4i)

Creates a reference-type attributed string from the specified value-type attributed string, including an attribute scope that a key path identifies.

[`- (instancetype) initWithFormat:(NSAttributedString *) format options:(NSAttributedStringFormattingOptions) options locale:(NSLocale *) locale;`](/documentation/Foundation/NSAttributedString/initWithFormat:options:locale:)

Initializes an attributed string by substituting arguments into a specially formatted string.

[`- (instancetype) initWithFormat:(NSAttributedString *) format options:(NSAttributedStringFormattingOptions) options locale:(NSLocale *) locale arguments:(va_list) arguments;`](/documentation/Foundation/NSAttributedString/initWithFormat:options:locale:arguments:)

Initializes an attributed string by substituting a list of function arguments into a specially formatted string.

[`- (instancetype) initWithFormat:(NSAttributedString *) format options:(NSAttributedStringFormattingOptions) options locale:(NSLocale *) locale context:(NSDictionary<NSString *,id> *) context;`](/documentation/Foundation/NSAttributedString/initWithFormat:options:locale:context:)

Initializes an attributed string by substituting arguments into a specially formatted string and applying additional contextual information.

[`- (instancetype) initWithFormat:(NSAttributedString *) format options:(NSAttributedStringFormattingOptions) options locale:(NSLocale *) locale context:(NSDictionary<NSString *,id> *) context arguments:(va_list) arguments;`](/documentation/Foundation/NSAttributedString/initWithFormat:options:locale:context:arguments:)

Initializes an attributed string by substituting a list of function arguments into a specially formatted string and applying additional contextual information.

[`+ (instancetype) localizedAttributedStringWithFormat:(NSAttributedString *) format;`](/documentation/Foundation/NSAttributedString/localizedAttributedStringWithFormat:)

Creates an attributed string by substituting arguments into a specially formatted string.

[`+ (instancetype) localizedAttributedStringWithFormat:(NSAttributedString *) format options:(NSAttributedStringFormattingOptions) options;`](/documentation/Foundation/NSAttributedString/localizedAttributedStringWithFormat:options:)

Creates an attributed string by substituting a list of function arguments into a specially formatted string.

[`+ (instancetype) localizedAttributedStringWithFormat:(NSAttributedString *) format context:(NSDictionary<NSString *,id> *) context;`](/documentation/Foundation/NSAttributedString/localizedAttributedStringWithFormat:context:)

Creates an attributed string by substituting arguments into a specially formatted string and applying additional contextual information.

[`+ (instancetype) localizedAttributedStringWithFormat:(NSAttributedString *) format options:(NSAttributedStringFormattingOptions) options context:(NSDictionary<NSString *,id> *) context;`](/documentation/Foundation/NSAttributedString/localizedAttributedStringWithFormat:options:context:)

Creates an attributed string by substituting a list of function arguments into a specially formatted string and applying additional contextual information.

[`enum NSAttributedStringFormattingOptions : NSUInteger;`](/documentation/Foundation/NSAttributedStringFormattingOptions)

Options to use when creating an attributed string from a format string and variable list of arguments.

### Creating from a data file

[`init(data: Data, options: [NSAttributedString.DocumentReadingOptionKey : Any], documentAttributes: AutoreleasingUnsafeMutablePointer<NSDictionary?>?) throws`](/documentation/Foundation/NSAttributedString/init(data:options:documentAttributes:))

Creates an attributed string from the contents of the specified data object.

[`init?(docFormat: Data, documentAttributes: AutoreleasingUnsafeMutablePointer<NSDictionary?>?)`](/documentation/Foundation/NSAttributedString/init(docFormat:documentAttributes:))

Creates an attributed string from Microsoft Word format data in the specified data object.

[`init(URL: URL, options: [NSAttributedString.DocumentReadingOptionKey : Any], documentAttributes: AutoreleasingUnsafeMutablePointer<NSDictionary?>?) throws`](/documentation/Foundation/NSAttributedString/init(URL:options:documentAttributes:))

Creates an attributed string from the contents of the specified URL.

### Creating from HTML

[`class func loadFromHTML(request: URLRequest, options: [NSAttributedString.DocumentReadingOptionKey : Any], completionHandler: (NSAttributedString?, [NSAttributedString.DocumentAttributeKey : Any]?, (any Error)?) -> Void)`](/documentation/Foundation/NSAttributedString/loadFromHTML(request:options:completionHandler:))

Creates an attributed string by converting the contents of the specified HTML URL request.

[`class func loadFromHTML(fileURL: URL, options: [NSAttributedString.DocumentReadingOptionKey : Any], completionHandler: (NSAttributedString?, [NSAttributedString.DocumentAttributeKey : Any]?, (any Error)?) -> Void)`](/documentation/Foundation/NSAttributedString/loadFromHTML(fileURL:options:completionHandler:))

Creates an attributed string by converting the content of a local HTML file at the specified URL.

[`class func loadFromHTML(string: String, options: [NSAttributedString.DocumentReadingOptionKey : Any], completionHandler: (NSAttributedString?, [NSAttributedString.DocumentAttributeKey : Any]?, (any Error)?) -> Void)`](/documentation/Foundation/NSAttributedString/loadFromHTML(string:options:completionHandler:))

Creates an attributed string from the specified HTML string.

[`class func loadFromHTML(data: Data, options: [NSAttributedString.DocumentReadingOptionKey : Any], completionHandler: (NSAttributedString?, [NSAttributedString.DocumentAttributeKey : Any]?, (any Error)?) -> Void)`](/documentation/Foundation/NSAttributedString/loadFromHTML(data:options:completionHandler:))

Creates an attributed string from the specified HTML data.

[`typealias CompletionHandler`](/documentation/Foundation/NSAttributedString/CompletionHandler)

A completion handler for getting an asynchronous attributed string.

[`init?(HTML: Data, documentAttributes: AutoreleasingUnsafeMutablePointer<NSDictionary?>?)`](/documentation/Foundation/NSAttributedString/init(HTML:documentAttributes:))

Creates an attributed string from the HTML in the specified data object.

[`init?(HTML: Data, baseURL: URL, documentAttributes: AutoreleasingUnsafeMutablePointer<NSDictionary?>?)`](/documentation/Foundation/NSAttributedString/init(HTML:baseURL:documentAttributes:))

Creates an attributed string from the HTML in the specified data object and base URL.

[`init?(HTML: Data, options: [NSAttributedString.DocumentReadingOptionKey : Any], documentAttributes: AutoreleasingUnsafeMutablePointer<NSDictionary?>?)`](/documentation/Foundation/NSAttributedString/init(HTML:options:documentAttributes:))

Creates an attributed string from the HTML in the specified data object.

### Creating from RTF

[`init?(RTF: Data, documentAttributes: AutoreleasingUnsafeMutablePointer<NSDictionary?>?)`](/documentation/Foundation/NSAttributedString/init(RTF:documentAttributes:))

Creates an attributed string by decoding the stream of RTF commands and data in the specified data object.

[`init?(RTFD: Data, documentAttributes: AutoreleasingUnsafeMutablePointer<NSDictionary?>?)`](/documentation/Foundation/NSAttributedString/init(RTFD:documentAttributes:))

Creates an attributed string by decoding the stream of RTFD commands and data in the specified data object.

[`init?(RTFDFileWrapper: FileWrapper, documentAttributes: AutoreleasingUnsafeMutablePointer<NSDictionary?>?)`](/documentation/Foundation/NSAttributedString/init(RTFDFileWrapper:documentAttributes:))

Creates an attributed string from the specified file wrapper that contains an RTFD document.

### Creating from markdown

[`convenience init(markdown: String, options: AttributedString.MarkdownParsingOptions, baseURL: URL?) throws`](/documentation/Foundation/NSAttributedString/init(markdown:options:baseURL:)-m9n)

Creates an attributed string from a Markdown-formatted string using the provided options.

[`convenience init(markdown: Data, options: AttributedString.MarkdownParsingOptions, baseURL: URL?) throws`](/documentation/Foundation/NSAttributedString/init(markdown:options:baseURL:)-5nru2)

Creates an attributed string from Markdown-formatted data using the provided options.

[`convenience init(contentsOf: URL, options: AttributedString.MarkdownParsingOptions, baseURL: URL?) throws`](/documentation/Foundation/NSAttributedString/init(contentsOf:options:baseURL:))

Creates an attributed string from the contents of a specified URL that contains Markdown-formatted data using the provided options.

[`- (instancetype) initWithMarkdownString:(NSString *) markdownString options:(NSAttributedStringMarkdownParsingOptions *) options baseURL:(NSURL *) baseURL error:(NSError **) error;`](/documentation/Foundation/NSAttributedString/initWithMarkdownString:options:baseURL:error:)

Creates an attributed string from a Markdown-formatted string using the provided options.

[`- (instancetype) initWithMarkdown:(NSData *) markdown options:(NSAttributedStringMarkdownParsingOptions *) options baseURL:(NSURL *) baseURL error:(NSError **) error;`](/documentation/Foundation/NSAttributedString/initWithMarkdown:options:baseURL:error:)

Creates an attributed string from Markdown-formatted data using the provided options.

[`- (instancetype) initWithContentsOfMarkdownFileAtURL:(NSURL *) markdownFile options:(NSAttributedStringMarkdownParsingOptions *) options baseURL:(NSURL *) baseURL error:(NSError **) error;`](/documentation/Foundation/NSAttributedString/initWithContentsOfMarkdownFileAtURL:options:baseURL:error:)

Creates an attributed string from the contents of a specified URL that contains Markdown-formatted data using the provided options.

[`@interface NSAttributedStringMarkdownParsingOptions : NSObject`](/documentation/Foundation/NSAttributedStringMarkdownParsingOptions)

Options that affect the parsing of Markdown content into an attributed string.

### Creating a string with an attachment

[`init(attachment: NSTextAttachment)`](/documentation/Foundation/NSAttributedString/init(attachment:))

Creates an attributed string with an attachment.

[`convenience init(attachment: NSTextAttachment, attributes: [NSAttributedString.Key : Any])`](/documentation/Foundation/NSAttributedString/init(attachment:attributes:))

Creates an attributed string with an attachment and applies the specified attributes to it.

[`convenience init(adaptiveImageGlyph: NSAdaptiveImageGlyph, attributes: [NSAttributedString.Key : Any])`](/documentation/Foundation/NSAttributedString/init(adaptiveImageGlyph:attributes:))

Creates an attributed string with an adaptive image glyph and applies the specified attributes to it.



---

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)