Swift Tour 随笔总结 (2)
Type Aliases
typealias AudioSample = UInt16
Booleans
非boolean值不会被替代为bool,例如:
let i = 1
if i {
// this example will not compile, and will report an error
}
Tuples
例如:HTTPStatus Code ("404", "Not Found")
let http404Error = (404, "Not Found")
// http404Error is of type (Int, String)
Access Tuple:
let (statusCode, statusMessage) = heep404Error
println("This status code is \(statusCode)")
// prints "The status code is 404"
println("The statuis message is \(statusMessage)")
// prints "The status message is Not Found"
简写,使用 _ 代替不需要的变量,例如:
let (justTheStatusCode, _) = http404Error
println("The status code is \(justTheStatusCode)")
// prints "The status code is 404"
另一种access tuple的方法:
println("The status code is \(http404Error.0)")
// prints "The status code is 404"
println("The status message is \(http404Error.1)")
// prints "The status message is Not Found"
Tuple的完整define
let http200Status = (statusCode: 200, description: "OK")
对应的access
println("The status code is \(http200status.statusCode)")
println("The status code message is \(http200status.description)")
Swift Tour 随笔总结 (2)的更多相关文章
- Swift Tour 随笔总结 (4)
Switch的一个例子: let vegetable = "red pepper" switch vegetable { case "celery": let ...
- Swift Tour 随笔总结 (3)
关于Optional的Control Flow if let constantName = someOptional { statements } 如果该Optional为nil,则不进入if,否则执 ...
- Swift Tour 随笔总结 (1)
let Constant var Variable let implicitInteger = 70 let implicitDouble = 70.0 let explicitDouble: Dou ...
- 【读书笔记】A Swift Tour
素材:A Swift Tour 推荐下载Playground:Download Playground objc 自己较为熟悉,想熟悉下风头正劲的 swift.就先从官方的入门手册开始撸. 每一小节,我 ...
- [IOS]《A Swift Tour》翻译(一)
以下翻译内容为原创,转载请注明: 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/3768936.html 碎碎念... Swift是苹果在WWDC刚发 ...
- Swift tour
输出函数: print(“hello world!") 无需引入函数库,无须使用“;”作为语句结尾,也无须写跟其它语言一样的main()函数,Swift中,全局区的代码就是程序入口.You ...
- A Swift Tour(3) - Functions and Closures
Functions and Closures 使用func来声明函数,通过括号参数列表的方式来调用函数,用 --> 来分割函数的返回类型,参数名和类型,例如: func greet(name: ...
- A swift Tour
传统的认为,一个新的语言的第一个应用程序都会打印"Hellow,Word",在Swift中,可以只需要一行代码: pringln("Hello, word") ...
- Swift学习——A Swift Tour 函数
Functions and Closures 函数和封闭性(闭包) Functions 函数的使用 Swift中的函数定义和OC中有明显的差别了,使用func定义函数,在括号里定义參数和类型,用 ...
随机推荐
- css3动画 bug 2点
1. .myanimate{ transition-property: left;transition-duration: .3s;transition-timing-function: ease } ...
- UITextField实现左侧空出一定的边距
就是通过uitextfield的leftview来实现的,同时要设置leftviewmode. 如果设置左右边距,需要再加上rightView功能 -(void)setTextFieldLeftPad ...
- promise与aysnc 与EventProxy
promise 已经是 es6推荐的内置的东西了,所以我们需要清楚. promise的使用类似与jquery的链式操作,.then() .then()中不断使用.回调看上去清晰明了,建议使用. as ...
- 附加到iis进程调试时找不到w3wp.exe
在进程列表的下面,有个show processes in all sessions,把它勾上就能看到了
- [BZOJ3504][CQOI2014]危桥(最大流)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3504 分析:很容易想到最大流,但如果S-a1,S-b1,a2-T,b2-T这样跑S-T最大流判 ...
- android之文件存储和读取
一.权限问题 手机中存储空间分为ROM和SDcard,ROM中放着操作系统以及我们安装的APP,而sdcard中一般放置着我们APP产生的数据.当然,Android也为每个APP在ROM中创建一个数据 ...
- [C#]Attribute特性
简介 特性提供功能强大的方法,用以将元数据或声明信息与代码(程序集.类型.方法.属性等)相关联. 特性与程序实体关联后,即可在运行时使用名为“反射”的技术查询特性. 特性具有以下属性: 特性可向程序中 ...
- jQuery应用之(三)jQuery链
从前文的实例中,我们按到jQuery语句可以链接在一起,这不仅可以缩短代码长度,而且很多时候可以实现特殊的效果. <script type="text/javascript" ...
- HTML5——多次定位请求
多次定位请求及点击一次 就不断的触发请求事件,和单次定位请求写法差不多,只需要将 navigator.geolocation.getCurrentPosition改为navigator.geoloca ...
- 传说中的WeixinJSBridge和微信rest接口
直接上图,金山的APP“微信导航”,从界面上看有粉丝数等关键数据,实现了直接关注功能,莫不是rest接口?这江湖是大佬们的江湖,小喽啰只有眼馋的份咯. 很早就听说过WeixinJSBridge,不过官 ...