μμ) currentSpeed μ makeNoise λ₯Ό κ°μ§κ³ μλ Vehicle class
class Vehicle {
var currentSpeed = 0.0
var description: String {
return "traveling at \(currentSpeed) miles per hour"
}
func makeNoise() {
// do nothing - an arbitrary vehicle doesn't necessarily make a noise
}
}
print("Vehicle: \(someVehicle.description)")
// Vehicle: traveling at 0.0 miles per hour
// Vehicle μ νλ‘νΌν°, λ©μλ, νΉμ§μ μ¬μ©νλ©΄μ,
// Bicycle λ§μ νλ‘νΌν°μΈ hasBasket λ μΆκ°.
class Bicycle: Vehicle {
var hasBasket = false
}
bicycle.currentSpeed = 15.0
print("Bicycle: \(bicycle.description)")
// Bicycle: traveling at 15.0 miles per hour
// νλ² subclassing λ κ²μ λ€μ subclassing κ°λ₯.
class Tandem: Bicycle {
var currentNumberOfPassengers = 0
}
override
ν€μλλ₯Ό λΆμ¬μ λΆλͺ¨μ κ²μ μ¬μ μ νλ κ²μμ μλ¦°λ€.super
ν€μλλ₯Ό μ¬μ©νλ€.super.someMethod
, super.someProperty
, super[someIndex]
class Train: Vehicle {
override func makeNoise() {
print("Choo Choo")
}
}
let train = Train()
train.makeNoise()
// Prints "Choo Choo" : μλ‘ μ μν λ΄μ©μ΄ μΆλ ₯λ©λλ€.
super.someProperty
μ²λΌ λΆλͺ¨μ μ κ·Όν΄μ κ°μ λ°μμ λ°ννμ.class Car: Vehicle {
var gear = 1
override var description: String {
return super.description + " in gear \(gear)"
}
}
class AutomaticCar: Car {
override var currentSpeed: Double {
didSet {
gear = Int(currentSpeed / 10.0) + 1
}
}
}
final
ν€μλλ₯Ό μ¬μ©νμ¬ μ€λ²λΌμ΄λλ₯Ό λ°©μ§νλ€.-> BaseVC κ°μ κ² λ§κ³ , λ§μ§λ§μΌλ‘ μ μΈνλ VCμλ final μ μ¨μ μ΅μ νλ₯Ό ν΄μ£Όμ.