(i) Type conversion
type conversions are more stringent in Swift, and can be considered as not mutually transforming between different types, and can only regenerate one object and value and copy one.
1.0 The conversion between integer values.
// different types cannot be added directly, then we need to use the type conversion A + Int16 (int8) print (int16)// output:
Again, it is possible to get the correct value through conversion, but it is worth noting that the conversion from a short to a long integer can be successful without losing value, and if a long integer is converted to a short integer, it may be unsuccessful.
Such as:
1234// error, cannot be converted because 1234 has exceeded the maximum value that the Int8 type can represent (127)
So Swift also suggests that we try to use Intinstead of explicitly using Int8, UInt,and so on.
2.0 conversion between integer and floating-point values
Let A:int // output 10.010.2// output 10, Therefore, the floating-point class to the integral type conversion, will lose the decimal point after the part, will lose the precision
so we can conclude that the accuracy of the high precision to the low conversion, will be lost, and vice versa.
(ii) type aliases
The so-called type alias: refers to a type to take an alias. Use the keyword typealias here .
Typealias myInt =//
Definition of Swift type conversions and type aliases (Typealias)