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

# read(from:ofType:)

Sets the contents of this document by reading from a file wrapper of a specified type.

## Declaration

```swift
nonisolated func read(from fileWrapper: FileWrapper, ofType typeName: String) throws
```

## Parameters

- `fileWrapper`: The file wrapper from which the document contents are read.
- `typeName`: The string that identifies the document type.

## Discussion

Discussion The default implementation of this method invokes [self readFromData:[fileWrapper regularFileContents] ofType:typeName error:outError]. For backward binary compatibility with OS X v10.3 and earlier, the default implementation of this method instead invokes [self loadFileWrapperRepresentation:fileWrapper ofType:typeName] if loadFileWrapperRepresentation:ofType: is overridden. 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:)-1vttv.md)
- [read(from:ofType:)](appkit/nsdocument/read(from:oftype:)-6g6ai.md)
