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定义函数,在括号里定义參数和类型,用 ...
 
随机推荐
- SpringMVC重定向视图RedirectView小分析
			
目录 前言 RedirectView介绍 实例讲解 总结 前言 SpringMVC是目前主流的Web MVC框架之一. 如果有同学对它不熟悉,那么请参考它的入门blog:http://www.cnbl ...
 - [原创]Net实现Excel导入导出到数据库(附源码)
			
关于数据库导出到Excel和SQLServer数据导出到Excel的例子,在博客园有很多的例子,自己根据网上搜集资料,自己做了亦歌简单的demo,现在分享出来供初学者学习交流使用. 一.数据库导入导出 ...
 - 风清杨之Oracle的安装与说明
			
1.Oracle官网与下载地址 Oracle中文官网:http://www.oracle.com/cn/index.html Oracle中文官网下载:http://www.oracle.com/te ...
 - JAVA中的NIO(二)
			
一.内存文件映射 内存文件映射允许我们创建和修改那些因为太大而不能放入内存中的文件.有了内存文件映射,我们就可以假定整个文件都在内存中,而且可以完全把文件当作数组来访问. package com.dy ...
 - Linux各目录作用
 - 由DataGridTextColumn不能获取到父级DataContext引发的思考
			
在项目中使用DataGrid需要根据业务动态隐藏某些列,思路都是给DataGrid中列的Visibility属性绑定值来实现(项目使用MVVM),如下 <DataGridTextColumn H ...
 - iOS---cell-自适应高度
			
RootViewController: // // RootViewController.m // UI__cell自适应高度 // // Created by dllo on 16/3/15. // ...
 - Canvas识别相似图片
			
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
 - 如何解决mysql数据库X小时无连接自动关闭
			
windows下打开my.ini,增加: interactive_timeout=28800000 wait_timeout=28800000 专家解答:MySQL是一个小型关系型数据库管理系统,由于 ...
 - POJ1459Power Network(dinic模板)
			
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 25832 Accepted: 13481 D ...