init(fileURL:options:documentAttributes:)
Initializes a new attributed string object from the data at the specified URL.
Declaration
init(fileURL url: URL, options: [AnyHashable : Any] = [:], documentAttributes dict: AutoreleasingUnsafeMutablePointer<NSDictionary?>?) throwsParameters
- url:
An
NSURLobject 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.
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.