wired up the ViewModel's SmallPhoto property change event with Combine

Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
Matt Bruce 2025-01-20 19:20:08 -06:00
parent 9d3a23e69d
commit 887cfd99ea

View File

@ -5,6 +5,7 @@
// Created by Matt Bruce on 1/20/25.
//
import UIKit
import Combine
public class EmployeeTableViewCell: UITableViewCell {
static let identifier = "EmployeeTableViewCell"
@ -14,6 +15,8 @@ public class EmployeeTableViewCell: UITableViewCell {
private let emailLabel = UILabel()
private let stackView = UIStackView()
private var cancellable: AnyCancellable?
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupUI()
@ -75,6 +78,13 @@ public class EmployeeTableViewCell: UITableViewCell {
public func configure(with viewModel: EmployeeCellViewModel) {
// Bind the image to the photoImageView
cancellable = viewModel.$smallPhoto
.receive(on: DispatchQueue.main)
.sink { [weak self] image in
self?.photoImageView.image = image
}
// Bind data to UI components
nameLabel.text = viewModel.fullName
emailLabel.text = viewModel.emailAddress