Calls the given closure with a pointer to the contents of the string, represented as a null-terminated sequence of UTF-8 code units.
SDK
- Xcode 7.0+
Framework
- Swift Standard Library
Declaration
func withCString<Result>(_ body: (Unsafe Pointer<Int8>) throws -> Result) rethrows -> Result
Parameters
bodyA closure with a pointer parameter that points to a null-terminated sequence of UTF-8 code units. If
bodyhas a return value, that value is also used as the return value for thewithmethod. The pointer argument is valid only for the duration of the method’s execution.CString(_:)
Return Value
The return value, if any, of the body closure parameter.
Discussion
The pointer passed as an argument to body is valid only during the execution of with. Do not store or return the pointer for later use.