枚举
enum Week{
case Mon
case Sun(String, Int, String)
func print(){
switch self{
case .Mon:
println("星期一")
case .Sun:
println("星期天")
}
}
}
var week1 = Week.Mon
week1.print()
var week2 = Week.Sun("one", 22, "two")
week2.print()
switch week1{
case let .Sun(a, b, c):
println("\(a),\(b),\(c)")
default:
break
}
switch week2{
case var .Sun(a, b, c):
println("\(a),\(b),\(c)")
default:
break
}
overridefunc didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
var stu1 =Student(name:"ldi", age:20, gender:"nv" )
var stu2 =Student(name:"lisi", age:30, gender:"男")
println("\(stu2.name):\(stu2.gender):\(Student.type)")
Student.type ="上课打开"
println("\(Student.type)")
stu1.name ="zhaoliu"
println("\(stu1.name):\(stu2.name)")
var stu3 = stu1//copy
stu3.name ="sjjde"
println("\(stu3.name):\(stu1.name)")
用代码显示按钮,实现动作
super.viewDidLoad()
var button:UIButton =UIButton.buttonWithType(UIButtonType.System)asUIButton//创建一个system类型的按钮
button.frame =CGRect(x:100, y:100, width:100, height:100)//设置按钮位置
button.setTitle("按钮", forState: UIControlState.Normal)//设置标题
button.setTitle("高亮", forState: UIControlState.Highlighted)
button.addTarget(self, action:"didClicked:", forControlEvents:UIControlEvents.TouchUpInside)//添加动作
self.view.addSubview(button)//显示按钮
}
func didClicked(sender:UIButton){
println("clik")