profile
개발자 만들기
post-thumbnail

[TIL]0822_swift Initializer(생성자)

Class Initializer(생성자) 부모, 자식 클래스 형태가 같음 상속된 자식클래스는 부모와 다른 생성자로 만들 수 있다. Inheritance(상속) 상속된 자식 클래스의 경우에도 생성시점에는 자신이 갖고 있는 property뿐만 아니라 부모의 property 값도 설정해줘야 한다 SubClass ▶️ SuperClass 2-phase Initialization(클래스 생성시 2가지 단계) 안지킬 시 원하는대로 동작 ❌, 버그 발생 Phase 1(자식 class property부터 initialization) Phase 1이 끝나기 전까지 어떤 property나 method를 쓸 수 없음 Person ◀️ Student ◀️ StudentAthlete(◀️super.init(...), self.sports=...) Phase 2 부모 class의 property를 다 세팅하고 나서(phas

2021년 8월 22일
·
0개의 댓글
·