Initializer

init(fileURL:options:documentAttributes:)

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

Declaration

init(fileURL url: URL, options: [AnyHashable : Any] = [:], documentAttributes dict: AutoreleasingUnsafeMutablePointer<NSDictionary?>?) throws

Parameters

url

An NSURL object specifying the document to load.

options

Document attributes for interpreting the document contents. documentType, characterEncoding, and defaultAttributes 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 documentType with a value of html). 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

init?(path: String, documentAttributes: AutoreleasingUnsafeMutablePointer<NSDictionary?>?)

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

Deprecated
init?(url: URL, documentAttributes: AutoreleasingUnsafeMutablePointer<NSDictionary?>?)

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

Deprecated
var containsAttachments: Bool

Returns whether the attribute string contains any attachment attributes.

Deprecated
func url(at: Int, effectiveRange: NSRangePointer) -> URL?

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
func draw(with: NSRect, options: NSString.DrawingOptions)

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

Deprecated
func boundingRect(with: NSSize, options: NSString.DrawingOptions) -> NSRect

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

Deprecated