A contiguously stored null-terminated UTF-8 representation of the string.
SDK
- Xcode 8.0+
Framework
- Swift Standard Library
Declaration
var utf8CString: ContiguousArray <CChar> { get }
Discussion
To access the underlying memory, invoke with
on the array.
let s = "Hello!"
let bytes = s.utf8CString
print(bytes)
// Prints "[72, 101, 108, 108, 111, 33, 0]"
bytes.withUnsafeBufferPointer { ptr in
print(strlen(ptr.baseAddress!))
}
// Prints "6"