Instance Method

readFromURL:options:documentAttributes:error:

Sets the contents of attributed string to the contents of the specified file.

Declaration

- (BOOL)readFromURL:(NSURL *)url options:(NSDictionary<NSAttributedStringDocumentReadingOptionKey, id> *)opts documentAttributes:(NSDictionary<NSAttributedStringDocumentAttributeKey, id> * _Nullable *)dict error:(NSError * _Nullable *)error;

Parameters

url

The URL of the file to read.

opts

The option keys for importing the document. For a list of possible values, see “Option keys for importing documents” in NSAttributedString.

dict

On return, contains the document attributes. For a list of possible values, see “Document Attributes” in NSAttributedString.

error

Upon return, if an error occurs, contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.

Return Value

YES if the attributed string is created successfully or NO if it was not.

Discussion

Filter services can be used to convert the contents of the URL into a format recognized by Cocoa.

For RTF formatted files, the contents of the file are appended to the previous string instead of replacing the previous string. Therefore, when using this method with existing content it's best to clear the content away explicitly.

See Also

Reading content

- readFromData:options:documentAttributes:error:

Sets the contents of the receiver from the stream at data.