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

# init(contentsOfFile:)

Initialize with the contents of a file.

## Declaration

```swift
init?(contentsOfFile file: String)
```

## Parameters

- `file`: The file to read.

## Discussion

Discussion Returns nil if there was an error reading the file.
