제13장: 방법 제14장: 구조와 분석 제15장: 유형 계승(322)
7746 단어 Swift 코드
// : 《 swift》
// : : :
//Create By ChenZhen
import Foundation
//class Account {
//
// var amount: Double = 10_000.00 //
// var owner: String = "Tony" //
// //
// func interesWithRate(rate: Double) -> Double {
// return rate * amount
// }
//}
//
//var myAccount = Account()
////
//print(myAccount.interesWithRate(rate: 0.088))
//
//class Employee {
// var no: Int = 0
// var name: String = ""
// var job: String?
// var salary: Double = 0
// var dept: Department?
//}
//
//class Department {
// var no: Int = 0
// var name: String = ""
// var employees: [Employee] = [Employee]()
//
// func insertWithObject(anObject: AnyObject, atIndex index: Int) ->() {
// let emp = anObject as! Employee
// employees.insert(emp, at:index)
// }
//}
//var dept = Department()
//
//var emp1 = Employee()
//dept.insertWithObject(anObject: emp1, atIndex: 0)
//
//var emp2 = Employee()
//dept.insertWithObject(anObject: emp2, atIndex: 0)
//
//var emp3 = Employee()
//dept.insertWithObject(anObject: emp3, atIndex: 0)
//
//print(dept.employees.count)
//
//class Employee {
// var no: Int = 0
// var name: String = ""
// var job: String?
// var salary: Double = 0
// var dept: Department?
//}
//struct Department {
// var no: Int = 0
// var name: String = ""
// var employees: [Employee] = [Employee]()
// // 。 ‘mutating’
// mutating func insertWithObject(anObject: AnyObject, atIndex index: Int) ->() {
// let emp = anObject as! Employee
// employees.insert(emp, at:index)
// }
//}
//struct Department {
// var no: Int = 0
// var name: String = ""
// var employees = NSMutableArray() //[Employee] = [Employee]()
// // 。 。
// func insertWithObject(anObject: AnyObject, atIndex index: Int) ->() {
// let emp = anObject as! Employee
// employees.insert(emp, at:index)
// }
//}
//var dept = Department()
//
//var emp1 = Employee()
//dept.insertWithObject(anObject: emp1, atIndex: 0)
//
//var emp2 = Employee()
//dept.insertWithObject(anObject: emp2, atIndex: 0)
//
//var emp3 = Employee()
//dept.insertWithObject(anObject: emp3, atIndex: 0)
//
//print(dept.employees.count)
//
//class RectangleA {
// var width: Double
// var height: Double
//
// init(W width: Double, H height: Double) {
// self.width = width
// self.height = height
// }
//}
//
//var recta = RectangleA(W: 320, H: 480)
//print(" A:\(recta.width) * \(recta.height)")
//
//class RectangleA {
// var width: Double
// var height: Double
//
// init(width: Double, height: Double) {
// self.width = width
// self.height = height
// }
//}
//
//var recta = RectangleA(width: 320, height: 480)
//print(" A:\(recta.width) * \(recta.height)")
// ,
//struct RectangleA {
// var width: Double
// var height: Double
//
//}
//
//var recta = RectangleA(width: 320, height: 480)
//print(" A:\(recta.width) * \(recta.height)")
//
//class RectangleA {
// var width: Double
// var height: Double
//
// init(width: Double, height: Double) {
// self.width = width
// self.height = height
// }
//
// init(W width: Double, H height: Double) {
// self.width = width
// self.height = height
// }
//
// init(length: Double) {
// self.width = length
// self.height = length
// }
//
// init() {
// self.width = 640.0
// self.height = 940.0
// }
//}
//
//var rectc1 = RectangleA(width: 320, height: 480)
//print(" A:\(rectc1.width) * \(rectc1.height)")
//
//var rectc2 = RectangleA(W: 330, H: 480)
//print(" A:\(rectc2.width) * \(rectc2.height)")
//
//var rectc3 = RectangleA(length:500.0)
//print(" A:\(rectc3.width) * \(rectc3.height)")
//
//var rectc4 = RectangleA()
//print(" A:\(rectc4.width) * \(rectc4.height)")
//
//struct RectangleA {
// var width: Double
// var height: Double
//
// init(width: Double, height: Double) {
// self.width = width
// self.height = height
// }
//
// init(W width: Double, H height: Double) {
// self.width = width
// self.height = height
// }
//
// init(length: Double) {
// self.init(W: length, H: length)
// }
//
// init() {
// self.init(width: 640.0, height: 940.0)
// }
//}
//
//var rectc1 = RectangleA(width: 320, height: 480)
//print(" A:\(rectc1.width) * \(rectc1.height)")
//
//var rectc2 = RectangleA(W: 330, H: 480)
//print(" A:\(rectc2.width) * \(rectc2.height)")
//
//var rectc3 = RectangleA(length:500.0)
//print(" A:\(rectc3.width) * \(rectc3.height)")
//
//var rectc4 = RectangleA()
//print(" A:\(rectc4.width) * \(rectc4.height)")
//
//class RectangleA {
// var width: Double
// var height: Double
//
// init(width: Double, height: Double) {
// self.width = width
// self.height = height
// }
//
// init(W width: Double, H height: Double) {
// self.width = width
// self.height = height
// }
//
// convenience init(length: Double) {
// self.init(W: length, H: length)
// }
//
// convenience init() {
// self.init(width: 640.0, height: 940.0)
// }
//}
//
//var rectc1 = RectangleA(width: 320, height: 480)
//print(" A:\(rectc1.width) * \(rectc1.height)")
//
//var rectc2 = RectangleA(W: 330, H: 480)
//print(" A:\(rectc2.width) * \(rectc2.height)")
//
//var rectc3 = RectangleA(length:500.0)
//print(" A:\(rectc3.width) * \(rectc3.height)")
//
//var rectc4 = RectangleA()
//print(" A:\(rectc4.width) * \(rectc4.height)")
// ,
//class RectangleA {
// var width: Double
// var height: Double
//
// init(width: Double, height: Double) {
// self.width = width
// self.height = height
// }
//
// init(W width: Double, H height: Double) {
// self.width = width
// self.height = height
// }
//
// deinit {
// print(" ...")
// self.width = 0.0
// self.height = 0.0
// }
//}
//
//var rectc1: RectangleA? = RectangleA(width: 320, height: 480)
//print(" A:\(rectc1!.width) * \(rectc1!.height)")
//rectc1 = nil
//
//var rectc2: RectangleA? = RectangleA(W: 330, H: 480)
//print(" A:\(rectc2!.width) * \(rectc2!.height)")
//rectc2 = nil
//
class Person {
var name: String
var age: Int
func description() -> String {
return "\(name) :\(age)"
}
convenience init() {
self.init(name: "tony")
self.age = 18
}
convenience init(name: String) {
self.init(name: name, age: 18)
}
init(name: String, age: Int) {
self.name = name
self.age = age
}
}
class Student: Person {
var school: String
init (name: String, age: Int, school: String) {
self.school = school
super.init(name: name, age: age)
self.name = " "
self.age = 21
}
convenience override init(name: String, age: Int) {
self.init(name: name, age: age, school: " ")
}
func toString() {
print("Student:\(school) \(name) \(age)")
}
}
let student = Student()
print(" :\(student.toString())")