Now init(bytesNoCopy is deprecated in macOS 13
The message says : String does not support no-copy initialization.
The problem with this depreciation is not so much the "no-copy" but 2 arguments that are no longer available.
There is case where length is useful , when we have to deal with part of string pointer.
And now its a problem to get it because there is no string initialization with length.
Yes we can do it with substring or using NSString
NSString.init(bytesNoCopy ...) as String
but it is not a good solution.
The other argument missing is "freeWhenDone" who avoid to do a "defer dealloc" when the String is returned from a function.
Last point, there can be no other type than UInt8 or Int8, but there are cases where for example in ascii UInt16 is used. (Process 2 bytes at a time )
Here is some suggestions :
init?(bytes: UnsafeMutableRawPointer, length: Int, encoding: String.Encoding, freeWhenDone flag: Bool )
if the length is nil then the pointer is null terminated.
init(utf8Bytes: UnsafePointer<UInt8>, length: Int?, freeWhenDone flag: Bool) init(utf8Bytes: UnsafePointer<Int8>, length: Int?, freeWhenDone flag: Bool)
Sometime it can be useful with bufferPointer
init(utf8BufferPointer: UnsafeBufferPointer<Int8>) init(utf8BufferPointer: UnsafeBufferPointer<UInt8>)
This depreciation was made by people who didn't think about the consequences and no alternative is offered.