---
title: "init(fileURL:options:documentAttributes:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nsattributedstring/init(fileurl:options:documentattributes:)"
---

# init(fileURL:options:documentAttributes:)

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

## Declaration

```swift
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. doc://com.apple.foundation/documentation/Foundation/NSAttributedString/DocumentAttributeKey/documentType, doc://com.apple.foundation/documentation/Foundation/NSAttributedString/DocumentAttributeKey/characterEncoding, and doc://com.apple.foundation/documentation/Foundation/NSAttributedString/DocumentAttributeKey/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

Return Value Returns an initialized attributed string object, or nil if the data can’t be decoded.

## Discussion

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. note: 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.

## See Also

### Deprecated Initializers

- [init(path:documentAttributes:)](foundation/nsattributedstring/init(path:documentattributes:).md)
- [init(URL:documentAttributes:)](foundation/nsattributedstring/init(url:documentattributes:).md)
