Instance Method

initWithFileURL:options:documentAttributes:error:

Initializes a new attributed string object from the data at the given URL.

Declaration

- (instancetype)initWithFileURL:(NSURL *)url options:(NSDictionary *)options documentAttributes:(NSDictionary * _Nullable *)dict error:(NSError * _Nullable *)error;

Parameters

url

An NSURL object specifying the document to load.

options

Document attributes for interpreting the document contents. NSDocumentTypeDocumentAttribute, NSCharacterEncodingDocumentAttribute, and NSDefaultAttributesDocumentAttribute are supported option keys. If not specified, the method examines the data to attempt to determine the appropriate attributes.

dict

If non-NULL, returns a dictionary with various document-wide attributes accessible via document attribute keys.

error

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

Return Value

Returns an initialized attributed string object, or nil if the data can’t be decoded.

Discussion

The HTML importer should not be called from a background thread (that is, the options dictionary includes NSDocumentTypeDocumentAttribute with a value of NSHTMLTextDocumentType). It will try to synchronize with the main thread, fail, and time out. Calling it from the main thread works (but can still time out if the HTML contains references to external resources, which should be avoided at all costs). The HTML import mechanism is meant for implementing something like markdown (that is, text styles, colors, and so on), not for general HTML import.

See Also

Deprecated Methods

+ textFileTypes

Returns an array of strings representing those file types that can be loaded as text.

Deprecated
+ textUnfilteredFileTypes

Returns an array of strings representing those file types that can be loaded as a text.

Deprecated
+ textPasteboardTypes

Returns an array of pasteboard types that can be loaded as text.

Deprecated
+ textUnfilteredPasteboardTypes

Returns an array of pasteboard types that can be loaded as text.

Deprecated
- initWithPath:documentAttributes:

Initializes a new attribute string object from RTF or RTFD data contained in the file at the given path.

Deprecated
- initWithURL:documentAttributes:

Initializes a new attributed string object from the data at the given URL.

Deprecated
containsAttachments

Returns whether the attribute string contains any attachment attributes.

Deprecated
- URLAtIndex:effectiveRange:

Returns a URL, either from a link attribute or from text at the given location that appears to be a URL string, for use in automatic link detection.

Deprecated
- drawWithRect:options:

Draws the receiver with the specified options, within the given rectangle in the current graphics context.

Deprecated
- boundingRectWithSize:options:

Calculates and returns bounding rectangle for the receiver drawn using the options specified, within the given rectangle in the current graphics context.

Deprecated