commented code

Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
Matt Bruce 2025-01-21 09:15:12 -06:00
parent 069cc8c06a
commit 6f7a43d15e

View File

@ -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