Type Method

stringEncoding(for: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

class func stringEncoding(for data: Data, encodingOptions opts: [StringEncodingDetectionOptionsKey : Any]? = nil, convertedString string: AutoreleasingUnsafeMutablePointer<NSString?>?, usedLossyConversion: UnsafeMutablePointer<ObjCBool>?) -> UInt

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

class var availableStringEncodings: UnsafePointer<UInt>

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

class var defaultCStringEncoding: UInt

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

class func localizedName(of: UInt)

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

func canBeConverted(to: UInt)

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

func data(using: UInt)

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

func data(using: UInt, allowLossyConversion: Bool)

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

var description: String

This NSString object.

var fastestEncoding: UInt

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

var smallestEncoding: UInt

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