//where let coordinate2 = (3,3) switch coordinate2 { case let (x,y) where x == y: println("(\(x),\(y)) is on the line x == y") case let (x,y) where x == -y: println("(\(x),\(y)) is on the line x == -y") case let (x,y): println("(\(x),\(y)) is just some arbitrary point.") } let courseInfo = ("3-2","区间运算符") switch courseInfo { case (_,let courseName) where courseName.hasSuffix("运算符"): println("课程《\(courseName)》是介绍运算符的课程") default: println("《\(courseInfo.1)》是其他课程") } let courseName = "区间运算符" switch courseName { case let str where str.hasSuffix("运算符"): println("课程《\(courseName)》是介绍运算符的课程") default: println("《\(courseInfo.1)》是其他课程") }
学过scala,发现swift借鉴functional programming的地方特别多。