1. Tuple types
Let cat = (age:4,weight:2,cocle: "Black", beauty:true)
if (cat.beauty) {
printf ("I will not tell you my kitten has \ (cat.age) years old, weight \ (cat.weight) Jin");
}else{
printf ("Come and let me chop you Up");
}
2.optional Unpacking and binding
var tickit = "5000000"//Here is a value, if it is "Luoshuailuo" after the ToInt () there is no value , the Swift is expressed in nil
var money = Tickit.toint ()//string string converted to reshape ToInt ()
var = "money1:string!" //Indirect unpacking, more commonly used in initialization of classes
If TickIT {
printf ("Congratulations to you, in the \ (Money!) Yuan "); //But here will be who optinal (5000000), not the value we want, so use unpacking to add after money!
}
So how do bindings work? Binding allows us to do more in the subsequent code (said the same as not said, add it later)
If var temp = money {
var after tax = double (temp) * 0.5//temp for int type 0.5 is double, error required conversion, for large range Double conversion
printf ("Congratulations on your (temp) yuan, the amount of money you pay after tax")
}
3. Assert: Generally in the program debugging time use, set certain conditions must meet, otherwise the program immediately terminates.
var age = 17
ASSERT (Age > 18, "must be greater than 18 years old to play this game")
Swift NOTE 2