---
title: "revert(toContentsOf:ofType:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsdocument/revert(tocontentsof:oftype:)"
---

# revert(toContentsOf:ofType:)

Discards all unsaved document modifications and replaces the document’s contents by reading a file or file package located by a URL of a specified type.

## Declaration

```swift
func revert(toContentsOf 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 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.
