标签:
//: Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
var a = 5
switch a {
case 4:
println("yes")
default:
println("nono")
}
var b = 11
//条件有冲突,只会执行排在前面的
//元组匹配
let point = (1,2)
switch point{
case (0,0):"在原点上"
case (_,0):"再x轴上"
case (0,_):"再y轴上"
case (-2...2,-2...2):"在指定范围以内"
default :"不在指定范围内"
}
let point1 = (1,2)
switch point1{
//变量只在本case语句中有效
case (let x,0):"再x轴上,值为\(x)"
case (0,let y):"再y轴上,值为\(y)"
case (let x,let y):"x值为\(x),y值为\(y)"
}
let point2 = (2,2)
switch point2{
//变量只在本case语句中有效
case let(x,y) where x==y:"x和y相等"
case let(x,y) where(x>0 && y>0):"点在第一象限"
case let(x,y):"x值为\(x),y值为\(y)"
}
标签:
原文地址:http://www.cnblogs.com/cxc-1314/p/4584629.html