extension

    Protocol Optional Function

    Swift의 프로토콜을 보면 Optional Funcion 이라는 것이 있다. 말 그대로 구현해도 되고 구현하지 않아도 되는 함수라는 뜻이다. protocol Dog { func bark() } extension Dog { func bark() { print("Bow-wow") } } final class Samoyed: Dog { init() { bark() } } Samoyed() 위 코드를 실행하면 “Bow-wow”를 출력하는 것을 볼 수 있다. 그런데 protocol은 구현체가 아닌데 어떻게 이게 가능할까? Protocols can be extended to provide method, initializer, subscript, and computed property implementations ..