withCString(encodedAs:_:)
Calls the given closure with a pointer to the contents of the string, represented as a null-terminated sequence of code units.
func withCString<Result, Encoding>(encodedAs targetEncoding: Encoding.Type, _ body: (UnsafePointer<Encoding.CodeUnit>) throws -> Result) rethrows -> Result where Encoding : _UnicodeEncoding
Parameters
- body
A closure with a pointer parameter that points to a null-terminated sequence of code units. If
body
has a return value, that value is also used as the return value for thewithCString(encodedAs:_:)
method. The pointer argument is valid only for the duration of the method’s execution.- targetEncoding
The encoding in which the code units should be interpreted.
Returns
The return value, if any, of the body
closure parameter.
The pointer passed as an argument to body
is valid only during the execution of withCString(encodedAs:_:)
. Do not store or return the pointer for later use.