Instance Method

data(from:documentAttributes:)

Returns an data object that contains a text stream corresponding to the characters and attributes within the given range.

Declaration

func data(from range: NSRange, documentAttributes dict: [NSAttributedString.DocumentAttributeKey : Any] = [:]) throws -> Data

Parameters

range

The range.

dict

A required dictionary specifying the document attributes. The dictionary contains values from Document Types and must at least contain documentType.

error

An in-out variable containing an encountered error, if any.

Return Value

Returns the data for the attributed string, or nil if failure. When nil, error encapsulates the error information.

Discussion

Raises an rangeException if any part of range lies beyond the end of the receiver’s characters.

See Also

Generating Data

func fileWrapper(from: NSRange, documentAttributes: [NSAttributedString.DocumentAttributeKey : Any]) -> FileWrapper

Returns an NSFileWrapper object that contains a text stream corresponding to the characters and attributes within the given range.

func docFormat(from: NSRange, documentAttributes: [NSAttributedString.DocumentAttributeKey : Any]) -> Data?

Returns a data object that contains a Microsoft Word–format stream corresponding to the characters and attributes within the specified range.

func rtf(from: NSRange, documentAttributes: [NSAttributedString.DocumentAttributeKey : Any]) -> Data?

Returns an NSData object that contains an RTF stream corresponding to the characters and attributes within the given range, omitting all attachment attributes.

func rtfd(from: NSRange, documentAttributes: [NSAttributedString.DocumentAttributeKey : Any]) -> Data?

Returns a data object that contains an RTFD stream corresponding to the characters and attributes within the range.

func rtfdFileWrapper(from: NSRange, documentAttributes: [NSAttributedString.DocumentAttributeKey : Any]) -> FileWrapper?

Returns an NSFileWrapper object that contains an RTFD document corresponding to the characters and attributes within the given range.