---
title: "read(from:options:documentAttributes:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsmutableattributedstring/read(from:options:documentattributes:)-54wth"
---

# read(from:options:documentAttributes:)

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

## Declaration

```swift
func read(from url: URL, options opts: [NSAttributedString.DocumentReadingOptionKey : Any] = [:], documentAttributes dict: AutoreleasingUnsafeMutablePointer<NSDictionary?>?) throws
```

```swift
func read(from url: URL, options opts: [NSAttributedString.DocumentReadingOptionKey : Any] = [:], documentAttributes dict: AutoreleasingUnsafeMutablePointer<NSDictionary?>?, error: ()) throws
```

## 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 doc://com.apple.foundation/documentation/Foundation/NSAttributedString.
- `dict`: On return, contains the document attributes. For a list of possible values, see “Document Attributes” in doc://com.apple.foundation/documentation/Foundation/NSAttributedString.
- `error`: Upon return, if an error occurs, contains an doc://com.apple.foundation/documentation/Foundation/NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.

## Discussion

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. note: In Swift, this method returns Void 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.

## See Also

### Reading Content

- [read(from:options:documentAttributes:)](foundation/nsmutableattributedstring/read(from:options:documentattributes:)-5mbcx.md)
