---
title: "init(fileURL:)"
framework: uikit
role: symbol
role_heading: Initializer
path: "uikit/uidocument/init(fileurl:)"
---

# init(fileURL:)

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

## Declaration

```swift
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

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

## Discussion

Discussion After you create a document object and no file exists for it yet, you should next call the 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:) after creating the document object. The second parameter of this method, the save operation constant, should be 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 for more information.

## See Also

### Related Documentation

- [fileURL](uikit/uidocument/fileurl.md)
