Contents

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