Instance Method

canBeConverted(to:)

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

Declaration

func canBeConverted(to encoding: UInt) -> Bool

Parameters

encoding

A string encoding. For possible values, see NSStringEncoding.

Return Value

true if the receiver can be converted to encoding without loss of information. Returns false if characters would have to be changed or deleted in the process of changing encodings.

Discussion

If you plan to actually convert a string, the dataUsingEncoding:... methods return nil on failure, so you can avoid the overhead of invoking this method yourself by simply trying to convert the string.

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 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.