---
title: "load(fromContents:ofType:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uidocument/load(fromcontents:oftype:)"
---

# load(fromContents:ofType:)

Loads the document data into the app’s data model.

## Declaration

```swift
func load(fromContents contents: Any, ofType typeName: String?) throws
```

## Parameters

- `contents`: An object encapsulating the document data to load. This object is either an instance of the doc://com.apple.documentation/documentation/Foundation/NSData class (for flat files) or the doc://com.apple.documentation/documentation/Foundation/FileWrapper class (for file packages).
- `typeName`: The file type of the document, a Uniform Type Identifier (UTI) based on the file extension of doc://com.apple.uikit/documentation/UIKit/UIDocument/fileURL. You can obtain the default value of the file type from the doc://com.apple.uikit/documentation/UIKit/UIDocument/fileType property.

## Discussion

Discussion Override this method to accept and load the data for a document. After UIDocument reads the document data from the file located at fileURL it calls your subclass, passing the data to the subclass in this method. This method is called on the queue that the open(completionHandler:) method was called on (typically, the main queue). 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 document data

- [open(completionHandler:)](uikit/uidocument/open(completionhandler:).md)
- [read(from:)](uikit/uidocument/read(from:).md)
