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

# read(from:ofType:)

Sets the contents of the receiver by reading from a file of a given type located by a given URL.

## Declaration

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

## Parameters

- `absoluteURL`: An URL that specifies the location from which to read the document.
- `typeName`: The document type at absoluteURL.

## Discussion

Discussion This method sets the URL for the persistent object store associated with the receiver’s managed object context to absoluteURL. 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

### Related Documentation

- [configurePersistentStoreCoordinator(for:ofType:modelConfiguration:storeOptions:)](appkit/nspersistentdocument/configurepersistentstorecoordinator(for:oftype:modelconfiguration:storeoptions:).md)

### Document Content Management

- [revert(toContentsOf:ofType:)](appkit/nspersistentdocument/revert(tocontentsof:oftype:).md)
- [write(to:ofType:for:originalContentsURL:)](appkit/nspersistentdocument/write(to:oftype:for:originalcontentsurl:).md)
