Returns an NSString object initialized using the characters in a given C array, interpreted according to a given encoding.


convenience init?(cString nullTerminatedCString: UnsafePointer<Int8>, encoding: UInt)



A C array of characters. The array must end with a NULL character; intermediate NULL characters are not allowed.


The encoding of nullTerminatedCString. For possible values, see NSStringEncoding.

Return Value

An NSString object initialized using the characters from nullTerminatedCString. The returned object may be different from the original receiver


If nullTerminatedCString is not a NULL-terminated C string, or encoding does not match the actual character encoding, the results are undefined.

Special Considerations

Only 8-bit encodings are supported, as encodings that have a greater width, such as UTF-16, may include a NULL byte in a single unit, which would result in the premature termination of the C string.

See Also

Related Symbols

class func string(withCString: UnsafePointer<Int8>)

Creates a new string using a given C-string.

init?(cStringNoCopy: UnsafeMutablePointer<Int8>, length: Int, freeWhenDone: Bool)

Initializes the receiver, a newly allocated NSString object, by converting the data in a given C-string from the default C-string encoding into the Unicode character encoding.

class var defaultCStringEncoding: UInt

Returns the C-string encoding assumed for any method accepting a C string as an argument.