<!--
{
  "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/read(from:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIDocument(im)readFromURL:error:"
  },
  "title" : "read(from:)"
}
-->

# read(from:)

Reads the document data in a file at a specified location in the application sandbox.

```
func read(from url: URL) throws
```

## Parameters

`url`

A file URL that identifies the location of the document file in the application sandbox. This file URL is typically the one returned by the [`fileURL`](/documentation/UIKit/UIDocument/fileURL) property.

## Discussion

Typical [`UIDocument`](/documentation/UIKit/UIDocument) subclasses shouldn’t need to call this method directly, especially if the entire file is read at once. The default implementation calls [`load(fromContents:ofType:)`](/documentation/UIKit/UIDocument/load(fromContents:ofType:)) on the queue on which [`open(completionHandler:)`](/documentation/UIKit/UIDocument/open(completionHandler:)) was called to provide the `UIDocument` subclass with the document data object.

Subclasses that want more control over the reading of the document file—for example, that want to read a large document file incrementally—can override this method. It isn’t necessary for these subclasses to call the superclass implementation (`super`).

> 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)