码迷,mamicode.com
首页 > 编程语言 > 详细

swift Switch

时间:2015-06-18 00:37:25      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:

//: 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)"

}

 

swift Switch

标签:

原文地址:http://www.cnblogs.com/cxc-1314/p/4584629.html

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