<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/InlineArray/init(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s11InlineArrayVsRi__rlEyAByxq_Gq_Siqd__YKXEqd__YKcs5ErrorRd__lufc"
  },
  "title" : "init(_:)"
}
-->

# init(_:)

Initializes every element in this array, by calling the given closure
with each index.

```
init<E>(_ body: (InlineArray<count, Element>.Index) throws(E) -> Element) throws(E) where E : Error
```

## Parameters

`body`

A closure that returns an owned `Element` to emplace at
the passed in index.

## Discussion

This will call the closure `count` times, where `count` is the static
count of the array, to initialize every element by passing the closure
the index of the current element being initialized.

```
InlineArray<4, Int> { $0 * 2 }  // [0, 2, 4, 6]
```

The closure is allowed to throw an error at any point during
initialization at which point the array will stop initialization,
deinitialize every currently initialized element, and throw the given
error back out to the caller.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)