---
title: "init(contentsOfFileAtURL:)"
framework: xctest
role: symbol
role_heading: Initializer
path: "xctest/xctattachment/init(contentsoffileaturl:)"
---

# init(contentsOfFileAtURL:)

Creates an attachment from the contents of an existing file on disk.

## Declaration

```swift
convenience init(contentsOfFileAtURL url: URL)
```

## Parameters

- `url`: The file URL from which data should be read to create the new attachment.

## Discussion

Discussion The attachment’s name property is the file name of the provided url. The attachment’s uniformTypeIdentifier value is inferred from the file’s extension. A default UTI of "public.data" is used for files without an extension. note: Use this initializer with files only. To create an attachment from a directory, use init(compressedContentsOfDirectoryAtURL:).

## See Also

### Creating Attachments from Files and Folders

- [init(contentsOfFileAtURL:uniformTypeIdentifier:)](xctest/xctattachment/init(contentsoffileaturl:uniformtypeidentifier:).md)
- [init(compressedContentsOfDirectoryAtURL:)](xctest/xctattachment/init(compressedcontentsofdirectoryaturl:).md)
