---
title: "read(from:ofType:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsdocument/read(from:oftype:)-1vttv"
---

# read(from:ofType:)

Sets the contents of this document by reading from a file or file package, of a specified type, located by a URL.

## Declaration

```swift
nonisolated func read(from url: URL, ofType typeName: String) throws
```

## Parameters

- `url`: The location from which the document contents are read.
- `typeName`: The string that identifies the document type.

## Discussion

Discussion The default implementation of this method just creates an NSFileWrapper and invokes [self readFromFileWrapper:theFileWrapper ofType:typeName error:outError]. For backward binary compatibility with OS X v10.3 and earlier, the default implementation of this method instead invokes [self readFromFile:[absoluteURL path] ofType:typeName] if readFromFile:ofType: is overridden and the URL uses the file: scheme. note: In Swift, this method is marked with the throws keyword to indicate that it throws an error in cases of failure. When overriding this method, use the throw statement to throw an NSError, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Reading the Document’s Content

- [canConcurrentlyReadDocuments(ofType:)](appkit/nsdocument/canconcurrentlyreaddocuments(oftype:).md)
- [read(from:ofType:)](appkit/nsdocument/read(from:oftype:)-3rzsi.md)
- [read(from:ofType:)](appkit/nsdocument/read(from:oftype:)-6g6ai.md)
