swift advanced pattern matching if case

let age = 22
let sex = "girl"

if (sex == "girl" && age >= 18 && age <= 25){
print("女朋友")
} else {
print("走你")
}

swift2 for we have added a new syntax: if case

Case 18 is ... 25 = IF Age {
Print ( "free")
} the else {
Print ( "without")
}

Where you can go through the Add Condition

Of course, is not required, swift2 provides criteria to filter syntax for us: where

Case 18 is ... 25 = IF WHERE Age Sex == "Girl" {
Print ( "Yes, the old iron")
} the else {
Print ( "go")
}

【swift】if case,guard case,for case
参考: https://www.jianshu.com/p/dc42bdbbf473

Guess you like

Origin www.cnblogs.com/sanjianghuiliu/p/11229308.html