Коды взяты из протокольно-ориентированного 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
переопределяет поведение по умолчанию SwitchWithTextCellDelegate
и SwitchWithTextCellDelegate
.
Затем автор настраивает ячейку, передавая viewModel
в качестве аргументов:
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. Может кто-нибудь объяснить
каковы названия и их значение
dataSource
иdelegate
configure
метода вSwitchWithTextTableViewCell
. ОниExternal Parameter Names
.почему тип передаваемых аргументов метода
configure
отличается: типыview model
иprotocols