The fastestEncoding
property returns the fastest encoding to which the string may be converted without loss of information.
string.fastestEncoding
This property returns an encoding which is the fastest encoding to which the string
may be converted without loss of information.
// import Foundationimport Foundation// creates some string valueslet str1 = "Welcome"let str2 = "to"let str3 = "Edpresso!"// get all encodings presentprint(String.availableStringEncodings)// get fastest encodingprint(str1.fastestEncoding)print(str2.fastestEncoding)print(str3.fastestEncoding)
Foundation
framework was imported.availableStringEncodings
property of the String class, we printed all available string encodings.fastestEncoding
property of the strings were gotten and printed to the console. Remember that this property returns the fastest encoding to which a string can be converted to without loss of information.The UTF-16 differs from other encodings because it uses a minimum of 2 bytes to represent a character in memory.