First, the number type:
Conversion between Swift numeric types Swift is a safe language, and for type checking is very strict and cannot be easily converted between different types.
1. Conversion between integers: In other languages such as C and objective-c, there are two methods for integral types
From the small range number to the large range number conversion is automatic;
Forcing conversions from a large number to a small range can result in the loss of data precision.
In Swift, these two methods do not work, we need to pass some functions for the display to convert, the code is as follows:
Let start:uint8=10;
Let end:uint16=20;
Let Total=start+end//This is wrong
Let Total=uint16 (Start) +end//Correct procedure 1
Let Total=start+uint8 (end)//correct procedure 2
Second, the Boolean data type:
The Boolean variable 2 is stored as a numeric form of 8 bits (one byte), but can only be true or false.
1. When called as a constructor (with operator new), Boolean () converts its arguments to a Boolean value and returns a Boolean containing the value.
2. If called as a function (without operator new), Boolean () will only convert its arguments to an original Boolean value and return this value.
The code is as follows:
Let Aa=true;
Let Bb=false;
Three, strings and characters
String is an ordered set of characters, such as "Hello,world". Swift strings are represented by a string type and can also be represented as a collection of character type values. Swift's string and character types provide a fast, Unicode-compatible way to handle textual information in code. The syntax for creating and manipulating strings is similar to the way C works, lightweight and readable. The string join operation only needs to pass the + number two strings next year. As with other values in swift, you can change the value of a string, depending on what is defined as a constant and variable.
The code is as follows:
Let's somestring= "Hello World";
Swift Basic Types