swift学习记录(switch)

来源:互联网 发布:怎么让淘宝店铺商品排名靠前 编辑:程序博客网 时间:2024/04/30 01:34

      switch 语法本身没有什么,让我感兴趣当有一点,就是swift的switch语法支持类似sql的用法,来看一下它书中的举例:

import Cocoa


let vegetable ="red pepper"

switch vegetable {

    case "celery":

        let vegetableComment ="Add some raisins and make ants on a log."

    case "cucumber","watercress":

        let vegetableComment ="That would make a good tea sandwich."

   case letwhere x.hasSuffix("pepper"):

       let vegetableComment ="Is it a spicy\(x)?"

    default :

        let vegetableComment ="Everything tastes good in soup."

}

      在case3中,类似sql的语法非常稀奇,如果能支持正则表达式那肯定是极好的。不需要在每个子句中加break也是极好的,就不知道它支不支持索引了,暂时留着这个问题,欢迎高手解答。
0 0