코드가 Protocol Oriented MVVM에서 가져 인수를 전달하고,이 ViewModel
이 같은 모습입니다 : 나는이 부분을 이해는 뷰 모델 또는 프로토콜
struct MinionModeViewModel: SwitchWithTextCellDataSource {
var title = "Minion Mode!!!"
var switchOn = true
}
extension MinionModeViewModel: SwitchWithTextCellDelegate {
func onSwitchTogleOn(on: Bool) {
if on {
print("The Minions are here to stay!")
} else {
print("The Minions went out to play!")
}
}
var switchColor: UIColor {
return .yellowColor()
}
}
. 기본적으로, MinionModeViewModel
인수로 viewModel
을 전달하여 몇 가지 기본 SwitchWithTextCellDelegate
의 행동과 SwitchWithTextCellDelegate
다음으로 저자는 셀을 구성하는 것입니다을 재정의 :
SettingsViewController.swift
let viewModel = MinionModeViewModel()
cell.configure(withDataSource: viewModel, delegate: viewModel)
return cell
을하지만, SwitchWithTextTableViewCell
에서 configure
메소드의 인수 SwitchWithTextCellDataSource
및 SwitchWithTextCellDelegate
있습니다
func configure(withDataSource dataSource: SwitchWithTextCellDataSource, delegate: SwitchWithTextCellDelegate?) {
self.dataSource = dataSource
self.delegate = delegate
label.text = dataSource.title
switchToggle.on = dataSource.switchOn
// color option added!
switchToggle.onTintColor = delegate?.switchColor
}
새로 워진 Swift. 누군가가 SwitchWithTextTableViewCell
에 configure
방법의
- 이름이 무엇인지
과 그 의미
dataSource
및delegate
을 설명해주십시오 수 있습니다. 그들은External Parameter Names
입니까? - 왜
configure
방법의 전달 인자의 종류가 다릅니다 :view model
protocols
대 유형