---
title: "init(contentsOf:encoding:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nsstring/init(contentsof:encoding:)"
---

# init(contentsOf:encoding:)

Returns an @c NSString object initialized by reading data from a given URL interpreted using a given encoding.

## Declaration

```swift
convenience init(contentsOf url: URL, encoding enc: UInt) throws
```

## Parameters

- `url`: The URL to read.
- `enc`: The encoding of the file at @c url.

## Return Value

Return Value An @c NSString object initialized by reading data from @c url. Returns @c nil if the URL can’t be opened or there is an encoding error.
