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定义函数,在括号里定义參数和类型,用 ...
随机推荐
- HoloLens开发手记 - Unity之Gestures手势识别
手势识别是HoloLens交互的重要输入方法之一.HoloLens提供了底层API和高层API,可以满足不同的手势定制需求.底层API能够获取手的位置和速度信息,高层API则借助手势识别器来识别预设的 ...
- [C/C++基础] C语言常用函数strlen的使用方法
函数声明:extern unsigned int strlen(char *s); 所属函数库:<string.h> 功能:返回s所指的字符串的长度,其中字符串必须以’\0’结尾 参数:s ...
- nodejs学习之文件上传
最近要做个图片上传的需求,因为服务端春节请假回家还没来,所以就我自己先折腾了一下,大概做出来个效果,后台就用了nodejs,刚开始做的时候想网上找一下资料,发现大部分资料都是用node-formida ...
- 微信第一个“小程序”亮相:不是APP胜似APP!
前天晚上,微信终于推出了“小程序”功能.看过效果演示之后,网友表示,好多App可以卸载了! 据了解,微信“小程序”已首批开放给200名拥有微信服务号的开发者进行内测,而且目前开发者发布的小程序无法在用 ...
- [codevs1283]等差子序列(二进制)
题目:http://codevs.cn/problem/1283/ 分析: 主要就是在每个判定上节省时间.一般的做法是开个数组记录每个数字出没出现,然后每次读入一个数字就以他为中间向两边扩展直到两个对 ...
- linux用户管理命令
关键字 useradd passwd who w uptime 1.useradd添加用户命令 useradd 用户名 passwd 用户名 (设置密码) 2.userdel 删除用户 userdel ...
- javascript基础知识拾遗
1 下面列出的值被当作假 false null undefined '' 0 NaN 其它所有值被当作是真 console.log(undefined || true); //true console ...
- Unknown column '' in 'field list'解决方案
很多人在用php+MySQL做网站往数据库插入数据时发现如下错误: 注册失败!Unknown column '1a' in 'field list' 结果发现用数字提交是没有问题的,其他如char型就 ...
- 关于js的string的3个函数slice,substring,substr对比
slice,substring,substr三个函数都是截取字符串,但是对参数的处理有区别 参数处理相似的两个函数式slice和substring slice(start,end)和substring ...
- [转]Oracle数据库中的约束
SQL 约束 约束用于限制加入表的数据的类型. 可以在创建表时规定约束(通过 CREATE TABLE 语句),或者在表创建之后也可以(通过 ALTER TABLE 语句). 我们将主要探讨以下几种约 ...