A: children's programming is not good!
B: most of them do not like learning. Starting from reading the English version, you will fall in love with programming!
Type aliases type redefinition (typedef)
The keyword of the type that is redefined in SWIFT is typealias. As for how to use it, you don't have to talk about it. Let's look at the example:
Typealias audiosample = uint16 // a type name audiosample is defined, representing the uint16 type var maxamplitudefound = audiosample. Min // maxamplitudefound is now 0
Booleans Boolean Type
Boolean has two values, true or false:
let orangesAreOrange = truelet turnipsAreDelicious = false
Haha, the literal meaning of the first constant is: Orange, the answer is true; the literal meaning of the second constant is: radish is delicious, and the answer is false.
It is estimated that the author does not like radishes or American radishes. In fact, there are many Chinese radishes that are delicious. Welcome to China, haha.
Oh, by the way, the original article also said that, unlike Int & Double, When you define a constant or variable as the bool type, if you assign true or false values, so we don't need to declare the bool type. Swift will judge it by itself (WIT ).
Of course, bool is the most commonly used in if statements:
if turnipsAreDelicious { println("Mmm, tasty turnips!")} else { println("Eww, turnips are horrible.")}// prints "Eww, turnips are horrible.
Note: In swift, other values are not allowed to replace bool, which means that in the Condition Statement, the condition can only be of the bool type, and Other types (such as 0, 1) it is not allowed. An error will be reported during compilation. It is said that this is done to make swift more secure.
Compilation error:
let i = 1if i { // this example will not compile, and will report an error}
Compiled version:
let i = 1if i == 1 { // this example will compile successfully}
Then, the original article explains why Swift does not allow the statement, which is different from other languages: it is still in consideration of security. Writing this statement can avoid unexpected errors, and ensure that the intention of the conditional statement is very clear.