码迷,mamicode.com
首页 > 其他好文 > 详细

swift官方文档中的switch中case let x where x.hasSuffix("pepper")是什么意思?

时间:2014-06-24 22:52:30      阅读:400      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   color   com   

在官方文档中,看到这句。但不明白什么意思。

 

let vegetable = "red pepper"

switch vegetable {
    
    case "celery":
    
        let vegetableComment = "Add some raisins and make ants on a log"
    
    case "cocumber", "watercress":
    
        let vegetableComment = "That would make a good tea sandwich."
    
    case let x where x.hasSuffix("pepper"):
    
        let vegetableComment = "Is it a spicy \(x)?"
    
    default:
    
        let vegetableComment = "Everything tastes good in soup.123321"
}

经过查资料,才发现这个是后缀的意思:

asPrefix:和hasSuffix:

前缀和后缀。

swift官方文档中的switch中case let x where x.hasSuffix("pepper")是什么意思?,布布扣,bubuko.com

swift官方文档中的switch中case let x where x.hasSuffix("pepper")是什么意思?

标签:style   class   blog   code   color   com   

原文地址:http://www.cnblogs.com/skiy/p/3805718.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!