来源:6-3 switch语句的高级用法

海河之家

2014-10-29 22:46

//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的地方特别多。

写回答 关注

2回答

  • l1uyub0b0b0
    2014-10-31 12:30:02

    现在这门课程的前六章已经根据swift正式版的最新语法(基于xcode6.1)进行了更新,同时最新添加了《3-2 nil聚合运算符》和《4-4 String.Index和Range》的最新内容,欢迎收听:)该课程的更新也即将登陆,敬请关注!

  • l1uyub0b0b0
    2014-10-30 11:04:05

    是的!感谢分享:)

玩儿转Swift

这套教程比任何的Swift中文教程深入,并且演示示例更丰富

57267 学习 · 512 问题

查看课程

相似问题

回答 2

回答 3

回答 1

回答 2

回答 2