required init fatal error - siwonkim0/ios-project-manager GitHub Wiki

required init fatal error ์ œ๊ฑฐ

fatalError๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ์ฝ”๋“œ๋ธ”๋Ÿญ์ด ๋‹น์žฅ ์‹คํ–‰๋  ์ผ์ด ์—†์–ด๋„, ํ–ฅํ›„ ์ฝ”๋“œ๋ฅผ ์Œ“๋‹ค๋ณด๋ฉด fatalError๊ฐ€ ๋งŽ์•„์งˆ ์ˆ˜ ์žˆ๊ณ , ๊ทธ๋กœ ์ธํ•ด ํฐ ํŒŒ์žฅ์„ ๊ฐ–๊ณ ์˜ฌ ์ˆ˜ ์žˆ๊ธฐ๋•Œ๋ฌธ์— ์ ˆ๋Œ€ ์˜ณ์ง€์•Š๋‹ค๋ผ๊ณ  ํŒ๋‹จ

๊ทธ๋ž˜์„œ ์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ์œ„ํ•ด ์ด๋‹ˆ์…œ๋ผ์ด์ €๋กœ ๋ฐ›๋Š” ํ”„๋กœํผํ‹ฐ๋ฅผ ์˜ต์…”๋„๋กœ ๋‘ฌ required init์—์„œ ๋‹ค์‹œ ์ดˆ๊ธฐํ™”ํ•ด์•ผ๋˜๋Š” ์ƒํ™ฉ์„ ๋ง‰๊ณ , fatalError๋ฅผ super.init(coder: coder) ์œผ๋กœ ๋ณ€๊ฒฝ

class ProjectListViewController: UIViewController {
    private var viewModel: ProjectViewModelProtocol

    init(viewModel: ProjectViewModelProtocol) {
        self.viewModel = viewModel
        super.init(nibName: nil, bundle: nil)
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
class ProjectListViewController: UIViewController {
    private var viewModel: ProjectViewModelProtocol?

    init(viewModel: ProjectViewModelProtocol) {
        self.viewModel = viewModel
        super.init(nibName: nil, bundle: nil)
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
}