title: Is there any way to initialize my tableViewCell with a model and use that inside the tableViewCell class to just populate the rest of properties?
body: <p>In the code below, I use a <code>didSet</code> to update the value of custom TableViewCell labels and image. </p>
  
  <p>I initially tried changing the <code>init</code> method of the my <code>ArtistTableViewCell</code>. I tried changing it to:</p>
  
  <pre><code>init(style: UITableViewCellStyle, reuseIdentifier: String?, artist: Artist) {
          self.artist = artist
  ...
  }
  </code></pre>
  
  <p>But that didn't work because it seems that the line:</p>
  
  <pre><code>let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! ArtistTableViewCell
  </code></pre>
  
  <p>wants to call a method with only this signature:</p>
  
  <pre><code>init(style: UITableViewCellStyle, reuseIdentifier: String?)
  </code></pre>
  
  <p>So my current code works. But it doesn't take <code>artist</code> as property to initialize with, is as below:</p>
  
  <pre><code>import UIKit
  
  class ArtistTableViewCell: UITableViewCell {
  
      var artist: Artist!{
          didSet{
              bioLabel.text = artist.bio
              nameLabel.text = artist.name
              artistImageView.image = artist.image
          }
      }
  
      lazy var bioLabel : UILabel = {
          let label = UILabel()
          label.translatesAutoresizingMaskIntoConstraints = false
          label.numberOfLines = 0
  
          return label
      }()
  
      lazy var nameLabel : UILabel = {
          let label = UILabel()
          label.backgroundColor = .cyan
          label.translatesAutoresizingMaskIntoConstraints = false
  
          return label
      }()
  
      lazy var artistImageView : UIImageView = {
          let imageView = UIImageView()
          imageView.translatesAutoresizingMaskIntoConstraints = false
  
          return imageView
      }()
  
      override func awakeFromNib() {
          super.awakeFromNib()
          // Initialization code
      }
  
      override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
  
          super.init(style: style, reuseIdentifier: reuseIdentifier)
  
          contentView.addSubview(bioLabel)
          contentView.addSubview(nameLabel)
          contentView.addSubview(artistImageView)
  
          NSLayoutConstraint.activate([
              bioLabel.leadingAnchor.constraint(equalTo: contentView.centerXAnchor, constant: 8),
              bioLabel.topAnchor.constraint(equalTo: contentView.topAnchor),
              bioLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -8),
              bioLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
              ])
          NSLayoutConstraint.activate([
              artistImageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor,constant: 8),
              artistImageView.topAnchor.constraint(equalTo: contentView.topAnchor),
              artistImageView.trailingAnchor.constraint(equalTo: contentView.centerXAnchor, constant: -8),
              artistImageView.bottomAnchor.constraint(equalTo: nameLabel.topAnchor, constant: -8)
              ])
  
          NSLayoutConstraint.activate([
              nameLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 8),
              nameLabel.trailingAnchor.constraint(equalTo:contentView.centerXAnchor, constant: -8),
              nameLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)            
              ])
      }
  
      required init?(coder aDecoder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
  
      override func setSelected(_ selected: Bool, animated: Bool) {
          super.setSelected(selected, animated: animated)
  
          // Configure the view for the selected state
      }
  
  }
  </code></pre>
  
  <p>This is how I call it:</p>
  
  <pre><code>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
      let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! ArtistTableViewCell
      let artist = artists[indexPath.row]
      cell.artist = artist        
  
      return cell
  }
  </code></pre>