---
title: "init(validatingUTF8:)"
framework: swift
role: symbol
role_heading: Initializer
path: "swift/string/init(validatingutf8:)-2m5lb"
---

# init(validatingUTF8:)

Creates a new string by copying and validating the null-terminated UTF-8 data referenced by the given array.

## Declaration

```swift
init?(validatingUTF8 cString: [CChar])
```

## Parameters

- `cString`: An array containing a null-terminated sequence of UTF-8 code units.

## Discussion

Discussion This initializer does not try to repair ill-formed UTF-8 code unit sequences. If any are found, the result of the initializer is nil. note: This initializer is deprecated. Use the initializer String.init?(validating: array, as: UTF8.self) instead, remembering that “\0” is a valid character in Swift.
