Last active
January 30, 2021 19:16
-
-
Save bigMOTOR/850984ff43a5a47fec2c94630f17a7f0 to your computer and use it in GitHub Desktop.
2021-01-30_Article_DataDrivenRxDatasources_3.swift
This file contains 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
final class XibCell: UITableViewCell, ModelledCell { | |
@IBOutlet weak var valueLabel: UILabel! | |
var cellModel: CellViewModel? { | |
didSet { | |
guard let viewModel = cellModel as? XibCellViewModel else { return } | |
self.valueLabel.text = viewModel.value | |
} | |
} | |
} | |
extension XibCellViewModel: CellViewModel { | |
var cellViewClass: CellType { | |
return .nibType(name: "\(XibCell.self)") | |
} | |
} |
This file contains 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
struct XibCellViewModel: SelectableType { | |
let value: String | |
let onSelected: (() -> Void)? | |
} | |
extension XibCellViewModel: IdentifiableCellViewModel { | |
var identity: Int { | |
return value.hash | |
} | |
func isEqual(to: IdentifiableCellViewModel) -> Bool { | |
guard let to = to as? XibCellViewModel else { return false } | |
return value == to.value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment