<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIDocument/load(fromContents:ofType:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIDocument(im)loadFromContents:ofType:error:"
  },
  "title" : "load(fromContents:ofType:)"
}
-->

# load(fromContents:ofType:)

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

```
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 [`fileURL`](/documentation/UIKit/UIDocument/fileURL). You can obtain the default value of the file type from the [`fileType`](/documentation/UIKit/UIDocument/fileType) property.

## 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`](/documentation/UIKit/UIDocument/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:)`](/documentation/UIKit/UIDocument/open(completionHandler:)) method was called on (typically, the main queue).

> Handling Errors in Swift:
> 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](https://docs.swift.org/swift-book/LanguageGuide/ErrorHandling.html) in [The Swift Programming Language](https://docs.swift.org/swift-book/) and `About Imported Cocoa Error Parameters`.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)