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

# init(contentsOf:usedEncoding:)

Returns an @c NSString object initialized by reading data from a given URL and returns by reference the encoding used to interpret the data.

## Declaration

```swift
convenience init(contentsOf url: URL, usedEncoding enc: UnsafeMutablePointer<UInt>?) throws
```

## Parameters

- `url`: The URL to read.
- `enc`: Upon return, if the URL is read successfully, contains the encoding used to interpret 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.
