Initializer

init(bytesNoCopy:length:encoding:freeWhenDone:)

Returns an initialized NSString object that contains a given number of bytes from a given buffer of bytes interpreted in a given encoding, and optionally frees the buffer.

Declaration

convenience init?(bytesNoCopy bytes: UnsafeMutableRawPointer, length len: Int, encoding: UInt, freeWhenDone freeBuffer: Bool)

Parameters

bytes

A buffer of bytes interpreted in the encoding specified by encoding.

length

The number of bytes to use from bytes.

encoding

The character encoding of bytes. For possible values, see NSStringEncoding.

flag

If true, the receiver releases the memory with free() when it no longer needs the data; if false it won’t.

Return Value

An initialized NSString object containing length bytes from bytes interpreted using the encoding encoding. The returned object may be different from the original receiver.

Discussion

If an error occurs during the creation of the string, then bytes is not freed even if flag is true. In this case, the caller is responsible for freeing the buffer. This allows the caller to continue trying to create a string with the buffer, without having the buffer deallocated.

See Also

Related Symbols

init?(bytes: UnsafeRawPointer, length: Int, encoding: UInt)

Returns an initialized NSString object containing a given number of bytes from a given buffer of bytes interpreted in a given encoding.