Type Method

stringEncodingForData:encodingOptions:convertedString:usedLossyConversion:

Returns the string encoding for the given data as detected by attempting to create a string according to the specified encoding options.

Declaration

+ (NSStringEncoding)stringEncodingForData:(NSData *)data encodingOptions:(NSDictionary<NSStringEncodingDetectionOptionsKey, id> *)opts convertedString:(NSString * _Nullable *)string usedLossyConversion:(BOOL *)usedLossyConversion;

Parameters

data

An NSData object containing bytes in an encoding to be determined.

opts

Options to use when attempting to determine the string encoding. See String Encoding Detection Options for a full list of supported options.

string

If a string encoding could be determined, upon return contains an NSString object constructed from data using the determined string encoding.

usedLossyConversion

If a string encoding could be determined, upon return contains a BOOL value corresponding to whether lossy conversion was used.

Return Value

An NSStringEncoding value, or 0 if a string encoding could not be determined.

See Also

Working with Encodings

availableStringEncodings

Returns a zero-terminated list of the encodings string objects support in the application’s environment.

defaultCStringEncoding

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

localizedNameOfStringEncoding:

Returns a human-readable string giving the name of a given encoding.

canBeConvertedToEncoding:

Returns a Boolean value that indicates whether the receiver can be converted to a given encoding without loss of information.

dataUsingEncoding:

Returns an NSData object containing a representation of the receiver encoded using a given encoding.

dataUsingEncoding:allowLossyConversion:

Returns an NSData object containing a representation of the receiver encoded using a given encoding.

description

This NSString object.

fastestEncoding

The fastest encoding to which the receiver may be converted without loss of information.

smallestEncoding

The smallest encoding to which the receiver can be converted without loss of information.