From 6f7a43d15e59ae420a5b71b7f7fe5553b2d456f8 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 21 Jan 2025 09:15:12 -0600 Subject: [PATCH] commented code Signed-off-by: Matt Bruce --- .../Views/EmployeeTableViewCell.swift | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/EmployeeDirectory/Views/EmployeeTableViewCell.swift b/EmployeeDirectory/Views/EmployeeTableViewCell.swift index f82fd4c..af15ad8 100644 --- a/EmployeeDirectory/Views/EmployeeTableViewCell.swift +++ b/EmployeeDirectory/Views/EmployeeTableViewCell.swift @@ -7,9 +7,17 @@ import UIKit import Combine +/// This is the Cell used in the EmployeesTableViewController to show +/// the properties of an Employee model. public class EmployeeTableViewCell: UITableViewCell { - static let identifier = "EmployeeTableViewCell" + /// Used in the TableView registration + static let identifier = "EmployeeTableViewCell" + + // MARK: - Properties + + + /// UI Elements private let photoImageView = UIImageView() private let nameLabel = UILabel() private let emailLabel = UILabel() @@ -19,7 +27,10 @@ public class EmployeeTableViewCell: UITableViewCell { private let bioLabel = UILabel() private let stackView = UIStackView() - private var cancellable: AnyCancellable? + /// Used for grabbing the photo + private var smallPhotoSubscriber: AnyCancellable? + + // MARK: - Initializer public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) @@ -30,6 +41,8 @@ public class EmployeeTableViewCell: UITableViewCell { fatalError("init(coder:) has not been implemented") } + // MARK: - Private Methods + private func setupUI() { // Configure photoImageView photoImageView.contentMode = .scaleAspectFill @@ -93,9 +106,13 @@ public class EmployeeTableViewCell: UITableViewCell { ]) } + // MARK: - Public Methods + + + /// Override for setting back to a default state public override func prepareForReuse() { super.prepareForReuse() - cancellable = nil + smallPhotoSubscriber = nil photoImageView.image = UIImage(systemName: "person.crop.circle") nameLabel.text = nil emailLabel.text = nil @@ -105,10 +122,12 @@ public class EmployeeTableViewCell: UITableViewCell { bioLabel.text = nil } + /// Configures the UI Elements with the properties of the EmployeeCellViewModel. + /// - Parameter viewModel: Employee Model wrapped for Cell. public func configure(with viewModel: EmployeeCellViewModel) { // Bind the image to the photoImageView - cancellable = viewModel.$smallPhoto + smallPhotoSubscriber = viewModel.$smallPhoto .receive(on: DispatchQueue.main) .sink { [weak self] image in self?.photoImageView.image = image