//main.swift
importFoundation
println("Hello, World!")
//(1)新建⼀一个Person类,给Person类定义三个属性name (String),age(Int),address(String),其中name是必选类型,age和address是可选类型,重载Person类的构造⽅方法
//如果一个类里面的方法是以init开头的,调用的时候后是有小括号
letperson0 = Person(name:"zhangsan", age:15, address:"xfghjf")
println(person0.name)
println(person0.age)
println(person0.address)
//(2)新建⼀一个Animal类,给Animal类定义三个属性type(String),age(Int),legs(Int),使⽤用KVC对其Animal对象进⾏行行赋值
//(3)找保姆,要求保姆完成:(代理理-协议)
//2.做饭。3.打扫房间。4.照看孩子
//Person.swift
importFoundation
//重载构造函数
classPerson:NSObject{
varname:String="zj"
varage:Int?
varaddress:String?
//重载构造函数(自定义初始化方法)
init(name:String,age:Int,address:String) {
self.name = name
super.init()
self.age = age
self.address = address
}
overrideinit() {
super.init()
}
}
//animal.swift
importFoundation
classAnimal:NSObject{
//定义属性
vartype:String
varage:Int
varlegs:Int
overrideinit() {
super.init()
}
}