Created
May 27, 2019 09:34
-
-
Save AppleCEO/4507047f8c3f21a0cad2591fbbd8b5ee to your computer and use it in GitHub Desktop.
부모 클래스의 모든 지정 이니셜라이저를 오버라이딩해준 경우 부모의 편의 이니셜라이저들도 상속되는 예제
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Food { | |
| var name: String | |
| init(name: String) { | |
| self.name = name | |
| } | |
| convenience init() { | |
| self.init(name: "[이름 없음]") | |
| } | |
| } | |
| class RecipeIngredient: Food { | |
| var quantity: Int | |
| init(name: String, quantity: Int) { | |
| self.quantity = quantity | |
| super.init(name: name) | |
| } | |
| override convenience init(name: String) { | |
| self.init(name: name, quantity: 1) | |
| } | |
| } | |
| let oneMysteryItem = RecipeIngredient() | |
| let oneBacon = RecipeIngredient(name: "베이컨") | |
| let sixEggs = RecipeIngredient(name: "달걀", quantity: 6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment