Initializes a new NSAttributed
object from the contents of the given URL.
SDKs
- iOS 9.0+
- macOS 10.4+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Frameworks
- UIKit
- App
Kit
Declaration
- (instancetype)initWithURL:(NSURL *)url options:(NSDictionary<NSAttributed String Document Reading Option Key, id> *)options documentAttributes:(NSDictionary<NSAttributed String Document Attribute Key, id> * _Nullable *)dict error:(NSError * _Nullable *)error;
Parameters
url
An
NSURL
object specifying the document to load.options
Specifies how the document should be loaded. Contains values described in Option keys for importing documents.
docAttributes
An in-out dictionary containing document-level attributes described in Document Attributes. May be
NULL
, in which case no document attributes are returned.error
An in-out parameter that returns an error if the method returns
nil
.
Return Value
Returns an initialized object, or nil
if the data can’t be decoded.
Discussion
Filter services can be used to convert the file into a format recognized by Cocoa. The options
dictionary specifies how the document should be loaded and can contain the values described in Option keys for importing documents.
If NSDocument
is specified, the document is treated as being in the specified format. If NSDocument
is not specified, the method examines the document and loads it using whatever format it seems to contain.
Also returns by reference in dict
a dictionary containing document-level attributes described in Document Attributes. The dict
parameter may be nil, in which case no document attributes are returned. Returns an initialized object, or nil
if the file at url
can’t be decoded, after setting error
to point to an NSError
object that encapsulates the reason why the attributed string object could not be created.
Handling Errors in Swift:
In Swift, this API is imported as an initializer and is marked with the throws
keyword to indicate that it throws an error in cases of failure.
You call this method in a try
expression and handle any errors in the catch
clauses of a do
statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.