swift,
http://gashero.iteye.com/blog/2075324
// Playground - noun: a place where people can play
//haha 没有分好,编译器推断类型,好玩,空格严格限制
import UIKit
var str = "Hello, playground"
println(str)
let label = "the width is"
let width = 94
let widthLabel = label + String(width)
var shoppingList = ["catfish","water"]
shoppingList[0]
var occupation = ["a":"bb"]
occupation["a"]
println(occupation)
let scores = [12,34,50]
for a in scores {
println(a)
if a==12 {
println("hello world")
}
}
let interestingNumbers = [
"Prime":[2,3,4],
"fibo":[1,5]
]
//字典可以这样遍历
for (kind,numbers) in interestingNumbers{
println(kind)
}
//->这符合太迷惑人了
func greet(name:String,day:String)->String{
return "hello world \(name),today is \(day)"
}
greet("bob", "tuesday")
func getPrices() ->(Double,Double,Double){
return (2.3,1,1)
}
getPrices()
//...代表可变的参数,这里面也有元组,哈哈,闭包的概念,就是传递函数指针,
class Shape{
var number = 0
func myFunc()->String{
return "a shape with \(number) sides"
}
}
var shape = Shape()
shape.number = 10
shape.myFunc()
//当一个语言讲了 定义变量常量,函数定义,类定义,对象,调用,数组字典,就等于讲完了,