init(capacity:)
Returns an initialized mutable data object capable of holding the specified number of bytes.
Declaration
init?(capacity: Int)Parameters
- capacity:
The number of bytes the data object can initially contain.
Return Value
An initialized NSMutableData object capable of holding capacity bytes. The returned object has the same memory alignment guarantees as malloc(_:).
Discussion
This method doesn’t necessarily allocate the requested memory right away. Mutable data objects allocate additional memory as needed, so capacity simply establishes the object’s initial capacity. When it does allocate the initial memory, though, it allocates the specified amount. This method sets the length of the data object to 0.
If the capacity specified in capacity is greater than four memory pages in size, this method may round the amount of requested memory up to the nearest full page.