[swift] 부모 클래스의 메서드를 자식 클래스에서 호출하는 방법

부모 클래스에서 정의된 메서드를 자식 클래스에서 호출하려면 super 키워드를 사용합니다. super 키워드를 사용하여 부모 클래스의 메서드를 호출할 수 있습니다.

다음은 부모 클래스의 메서드를 호출하는 예제입니다.

class ParentClass {
    func myMethod() {
        print("부모 클래스의 메서드")
    }
}

class ChildClass: ParentClass {
    func callParentMethod() {
        super.myMethod() // 부모 클래스의 메서드 호출
    }
}

let childObject = ChildClass()
childObject.callParentMethod() // "부모 클래스의 메서드" 출력

위 예제에서 callParentMethod 메서드는 super.myMethod()를 사용하여 부모 클래스의 myMethod를 호출합니다.

이와 같이 super 키워드를 사용하여 부모 클래스의 메서드를 호출할 수 있습니다.

참고: The Swift Programming Language - Inheritance