From 887cfd99eab4e9f3c148b5ce960ad840998a72d3 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 20 Jan 2025 19:20:08 -0600 Subject: [PATCH] wired up the ViewModel's SmallPhoto property change event with Combine Signed-off-by: Matt Bruce --- EmployeeDirectory/Views/EmployeeTableViewCell.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/EmployeeDirectory/Views/EmployeeTableViewCell.swift b/EmployeeDirectory/Views/EmployeeTableViewCell.swift index 04d6072..066adee 100644 --- a/EmployeeDirectory/Views/EmployeeTableViewCell.swift +++ b/EmployeeDirectory/Views/EmployeeTableViewCell.swift @@ -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