Skip to content

Convenience init에 대해 설명하시오. #11

Open

Description

@Glsme

convenience init

지정 생성자보다 더 적은 개수의 파라미터로 보다 편리하게 생성하기 위한 생성자이다.

  • 초기화 과정을 간편하게 제공하기 위함이다.
  • 편의생성자의 경우 서브클래스에서 재정의를 못한다. (Override 불가능, 하위 클래스에서 호출불가가 원칙이다.)
  • 구조체(열거형)의 경우, convenience 키워드를 붙이지 않아도 다른 생성자를 호출이 가능하기 때문에 사용이 불가능하다.

동작 방식

Convenienceinit

  • convenience init()이 호출되면 지정 생성자를 호출한다.
  • 만약, 상위 클래스가 있다면, super.init()을 호출한다.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions