Initializer

init(unsafeUninitializedCapacity:initializingWith:)

Creates an array with the specified capacity, then calls the given closure with a buffer covering the array’s uninitialized memory.

Declaration

init(unsafeUninitializedCapacity: Int, initializingWith initializer: (inout UnsafeMutableBufferPointer<Element>, inout Int) throws -> Void) rethrows

Parameters

unsafeUninitializedCapacity

The number of elements to allocate space for in the new array.

initializer

Discussion

Inside the closure, set the initializedCount parameter to the number of elements that are initialized by the closure. The memory in the range buffer[0..<initializedCount] must be initialized at the end of the closure’s execution, and the memory in the range buffer[initializedCount...] must be uninitialized. This postcondition must hold even if the initializer closure throws an error.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software