---
title: "init(data:)"
framework: cryptokit
role: symbol
role_heading: Initializer
path: "cryptokit/aes/gcm/nonce/init(data:)"
---

# init(data:)

Creates a nonce from the given data.

## Declaration

```swift
init<D>(data: D) throws where D : DataProtocol
```

## Parameters

- `data`: A data representation of the nonce. The initializer throws an error if the data has a length smaller than 12 bytes.

## Discussion

Discussion Unless your use case calls for a nonce with a specific value, use the init() method to instead create a random nonce.

## See Also

### Creating a nonce

- [init()](cryptokit/aes/gcm/nonce/init().md)
