Created
June 7, 2014 17:58
-
-
Save mani95lisa/f0eb3b8030ed5b4d5c88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//变量、常量、字符串、println | |
var 变量 = "变量" //可以用Unicode编码声明变量或常量了,但不推荐 | |
var variable : String | |
var variableWithoutType = "无类型必初始化,自动继承值的类型" | |
let const = "常量必须初始化" | |
var interpolation = "字符串插入\(const)" | |
println("输出结果到控制台:\(interpolation)");println("分号仅用于分隔一行里的多语句,不建议这样使用") | |
//数 | |
println(UInt8.min, UInt8.max) //(0, 255) | |
//32位系统Int等同于Int32,64等同于Int64,UInt同理,为非负数,最大值为两倍Int最大值 | |
println(Int.min, Int.max, UInt.max) | |
//Double和Float精度不一,数值范围也比Int和UInt大非常多 | |
let double = 0.12345678901234567 //默认继承Double类型 | |
let float:Float = 0.12345678901234567 | |
println(float) //print 0.123456791043282 | |
println(double) //print 0.123456789012346 | |
var int = 1 | |
int = Int(double)+int //运算需强制转换数据类型 | |
//类型别名 | |
typealias AudioSample = UInt16 | |
let maxAmplitudeFound:AudioSample = AudioSample.max | |
//元组 | |
let error = (404, "页面未找到") //error类型为 (Int,String) | |
let (code, message) = error | |
println("错误状态码:\(code) 消息:\(message)") | |
//错误状态码:404 消息:页面未找到 | |
let (onlyCode, _) = error | |
println("只需要提取状态码\(onlyCode),使用_符号来充数") | |
//只需要提取状态码404,使用_符号来充数 | |
println("也可以直接获取状态码:\(error.0) 消息:\(error.1)") | |
let success = (code:200, message:"请求成功") | |
println("定义参数后可以通过参数来获取状态码:\(success.code)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment