minjae-L / showWeather

날씨 알려주는 앱
0 stars 0 forks source link

present하여 뷰 이동시 뷰모델 부여하는 방법? #4

Open minjae-L opened 2 months ago

minjae-L commented 2 months ago
        let vc = WeatherViewController()
        vc.viewModel.completion = suggestion
        vc.viewModel.address = viewModel.elements[indexPath.row].addressLabel
        self.present(vc,animated: true)

뷰 이동시 뷰모델을 부여하는 방법은 어떤게 있을까

Key5771 commented 2 months ago

ViewController의 생성자가 이런 형태면 어떨까?

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

required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}