, , .
bark() , . , , :
protocol Bark {
func bark()
}
extension Bark {
func bark() { print("Bark") }
}
class Dog: Bark {}
class Poodle: Dog {
func bark() { print("Yap") }
}
class GermanShephard: Dog {
func bark() { print("Woof") }
}
let dog = Dog()
let poodle = Poodle()
let germanShephard = GermanShephard()
dog.bark()
poodle.bark()
germanShephard.bark()
- .
:
, . , . , , Dog DogRepresentable , . DogRepresentable, self: UIViewController :
protocol Barkable {
func bark()
}
protocol DogRepresentable: Barkable {
}
extension DogRepresentable where Self: UIViewController {
}
Barkable DogRepresentable, , , DogRepresentable, Barkable.
, DogRepresentable , , , bark() :
class Dog: DogRepresentable {
func bark() { print("Bark") }
}
class Poodle: DogRepresentable {
func bark() { print("Yap") }
}
class GermanShephard: DogRepresentable {
}
, , .
2 :
DogRepresentable Barkable, : , Yappable, . Barkable . , . Yappable, Barkable.
, , , , .