常见的数据类型
初探
let age = 10
//浮点数
let letFloat: Float = 30.0
let letDouble = 30.0
let bool = true
let string = "我我我"
//字符类型
let character: character = "够"
let array = [1,3,4,5,8]
let dictionary = ["age" : 18, "height" : 168, "weight": 120]
//元祖
let http404Error = (404, "Not Found")
print ("the status code is \(http404Error.0)")
let http200Status = (statusCode: 200, description: "ok")
print("the status code is \ (http200Status.statusCode)")
函数
func pi() -> Double{
return 3.14
}
func sum(v1: Int, v2: Int) -> Int {
return v1 + v2
}
func sayhellod() -> void
{
}
func sayhellod1() -> ()
{
}
func sayhellod3()
{
}
//隐式返回
func sayHello4(v1: Int, v2: Int) -> Int {
v1 + v2
}
sayHello4(v1: 10, v2: 20)