class calculations {
let a: Int
let b: Int
let res: Int
init(a: Int, b: Int) {
self.a = a
self.b = b
res = a + b
print("Self 内: \(res)")
}
func tot(c: Int) -> Int {
return res - c
}
func result() {
print("结果为: \(tot(c:20))") //swift 3.0 版本之前是 print("结果为: \(tot(20))")
print("结果为: \(tot(c:50))") //swift 3.0 版本之前是 print("结果为: \(tot(50))")
}
}
let pri = calculations(a: 600, b: 300)
let sum = calculations(a: 1200, b: 300)
pri.result()
sum.result()