---
title: "init(size:initializingWith:)"
framework: cryptokit
role: symbol
role_heading: Initializer
path: "cryptokit/symmetrickey/init(size:initializingwith:)"
---

# init(size:initializingWith:)

Creates a new key of the given size where the key contents are initialized via a callback.

## Declaration

```swift
init<E>(size: SymmetricKeySize, initializingWith callback: @_lifetime(0: copy 0) (inout OutputRawSpan) throws(E) -> Void) throws(E) where E : Error
```

## Parameters

- `size`: The size of the key to generate. You can use one of the standard sizes, like doc://com.apple.CryptoKit/documentation/CryptoKit/SymmetricKeySize/bits256, or you can create a key of custom length by initializing a doc://com.apple.CryptoKit/documentation/CryptoKit/SymmetricKeySize instance with a non-standard value.
- `callback`: A callback that will be invoked to initialize the contents of the key. It must initialize the full set of size.bitCount / 8 bytes in the provided output span.
