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

# init(contentsOfFile:)

## Declaration

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

## Discussion

Discussion Creates an attachment with an existing file on disk. Attachment’s uniform type identifier is inferred from the file extension. If no type can be inferred from the extension, fallback is “public.data”. note: Only works for files, not directories.
