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

# read(from:ofType:)

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

## Declaration

```swift
nonisolated func read(from data: Data, ofType typeName: String) throws
```

## Parameters

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

## Discussion

Discussion The default implementation of this method throws an exception because at least one of the three reading methods (this method, read(from:ofType:), read(from:ofType:)), or every method that may invoke read(from:ofType:), must be 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:)-3rzsi.md)
