//main.swift
importFoundation
println("Hello, World!")
//(1)新建?一個Person類,給Person類定義三個屬性name (String),age(Int),address(String),其中name是必選類型,age和address是可選類型,重載Person類的構(gòu)造?方法
//如果一個類里面的方法是以init開頭的,調(diào)用的時候后是有小括號
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對象進(jìn)?行行賦值
//(3)找保姆,要求保姆完成:(代理理-協(xié)議)
//2.做飯屿岂。3.打掃房間牍戚。4.照看孩子
//Person.swift
importFoundation
//重載構(gòu)造函數(shù)
classPerson:NSObject{
varname:String="zj"
varage:Int?
varaddress:String?
//重載構(gòu)造函數(shù)(自定義初始化方法)
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()
}
}