<!--
{
  "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/init(fileURL:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIDocument(im)initWithFileURL:"
  },
  "title" : "init(fileURL:)"
}
-->

# init(fileURL:)

Returns a document object initialized with its file-system location.

```
init(fileURL url: URL)
```

## Parameters

`url`

A file URL identifying the location in the application sandbox where document data is to be written. Passing in `nil` or an empty URL results in the throwing of an <doc://com.apple.documentation/documentation/Foundation/NSExceptionName/invalidArgumentException>.

## Return Value

A `UIDocument` object or `nil` if the object could not be created.

## Discussion

After you create a document object and no file exists for it yet, you should next call the [`save(to:for:completionHandler:)`](/documentation/UIKit/UIDocument/save(to:for:completionHandler:)) to write the document to its file-system location in the application sandbox. If `url` locates an existing document file, call [`open(completionHandler:)`](/documentation/UIKit/UIDocument/open(completionHandler:)) after creating the document object. The second parameter of this method, the save operation constant, should be [`UIDocument.SaveOperation.forCreating`](/documentation/UIKit/UIDocument/SaveOperation/forCreating) when there is no document file yet. In the completion handler, if you want the document to be automatically synced with other devices you should ensure that its URL is based in a ubiquitous container; see [Designing for Documents in iCloud](https://developer.apple.com/library/content/documentation/General/Conceptual/iCloudDesignGuide/Chapters/DesigningForDocumentsIniCloud.html#//apple_ref/doc/uid/TP40012094-CH2-SW1) for more information.

## See Also

[`fileURL`](/documentation/UIKit/UIDocument/fileURL)

The file URL you use to initialize the document.



---

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)