Swift learn 3
来源:互联网 发布:用友软件使用说明 编辑:程序博客网 时间:2024/05/21 17:59
Swift基础学习
// Playground - noun: a place where people can playimport UIKit//如果你不需要知道区间内每一项的值,你可以使用下划线(_)替代变量名来忽略对值的访问for _ in 1...5{ println("this is _");}for var i=0; i<5; ++i{ println("value:\(i)");}var num = 10;while num-- > 0 { println(num);}//switch语句必须是完备的。这就是说,每一个可能的值都必须至少有一个 case 分支与之对应。在某些不可能涵盖所有值的情况下var name:String = "Michael";switch name{case "MZ": println("This is MZ"); case "Michael": println(name); default: println("default");}//case 分支的模式也可以是一个值的区间var testNum = 10000;switch testNum{case 0...9: println("0...9"); case 10...9998: println("10...9998"); case 9999...100000: println("9999...100000"); default: println("default");}//你可以使用元组在同一个switch语句中测试多个值。元组中的元素可以是值,也可以是区间。//这个判断坐标很有效let points = (1, 1)switch points {case (0, 0): println("(0, 0) is at the origin")case (_, 0): println("(\(points.0), 0) is on the x-axis")case (0, _): println("(0, \(points.1)) is on the y-axis")case (-2...2, -2...2): println("(\(points.0), \(points.1)) is inside the box")default: println("(\(points.0), \(points.1)) is outside of the box")}//case 分支的模式可以使用where语句来判断额外的条件。let point0 = (1, -1)switch point0 {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) where x*x == y: println("(\(x), \(y)) is on the line x*x == y"); case let (x, y): println("(\(x), \(y)) is just some arbitrary point");default: println("default value");}//控制转移语句改变你代码的执行顺序,通过它你可以实现代码的跳转。Swift有四种控制转移语句。//continue//break//fallthrough Swift 中的switch不会从上一个 case 分支落入到下一个 case 分支中。相反,只要第一个匹配到的 case 分支完成了它需要执行的语句,整个switch代码块完成了它的执行。//return
0 0
- Swift learn 3
- Swift learn 1
- swift learn 2
- Swift learn 4
- Swift learn 5
- Swift learn 6
- Swift learn 7
- Swift learn 8
- SwiftBasicSyntax-Learn Swift(First Day)
- Learn Computer Science with Swift.pdf 英文原版 免费下载
- Learn Python 3 笔记
- learn vi【3】
- Learn in FCC(3)
- Spring learn note 3
- learn
- learn
- IOS Apps 开发(Swift)(2)——Learn the Essentials of Swift(1)
- IOS Apps 开发(Swift)(2)——Learn the Essentials of Swift(2)
- 自定义类加载器的实现,类加载过程
- EF codefirst数据迁移
- 用自定义keystore调试安卓应用(如微信分享等功能)
- DHTNL中window对象一些常用的属性和方法
- 4 款消息队列软件产品大比拼
- Swift learn 3
- three.js 源码注释(二十五)Core/Geometry.js
- 【C++】趴一趴程序内存管理
- MySQL 高可用架构在业务层面的分析研究
- IOS学习之NSArray和NSMutableArray详解
- 【乐易考看在线】上市公司纷纷跨界押宝 在线教育能否成上市公司转型跳板
- BZOJ 3721 PA 2014 Final Bazarek 贪心
- 查看SELinux状态技巧与SELinux关闭方法
- Java 7 Fork/Join 框架