Creates an “external representation” of a CFString object, that is, a CFData object.
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
- Core Foundation
The allocator to use to allocate memory for the new CFData object. Pass
kto use the current default allocator.
The string to convert to an external representation.
The string encoding to use for the external representation.
The character value to assign to characters that cannot be converted to the requested encoding. Pass
0if you want conversion to stop at the first such error; if this happens, the function returns
A CFData object that stores the characters of the CFString object as an “external representation.” Returns
NULL if no loss byte was specified and the function could not convert the characters to the specified encoding. Ownership follows the The Create Rule.
In the CFData object form, the string can be written to disk as a file or be sent out over a network. If the encoding of the characters in the data object is Unicode, the function may insert a BOM (byte-order marker) to indicate endianness. However, representations created with encoding constants
k do not include a BOM because the byte order is explicitly indicated by the letters “BE” (big-endian) and “LE” (little-endian).
This function allows the specification of a “loss byte” to represent characters that cannot be converted to the requested encoding.
When you create an external representation from a CFMutableString object, it loses this mutability characteristic when it is converted back to a CFString object.
CFString function complements this function by creating a CFString object from an “external representation” CFData object.