title: Creating single .xib for different UITableViewCell classes
body: <p>I am facing a problem </p>
  
  <p>I have a <code>NNVerticalStackTableViewCell.xib</code> file and its corresponding <code>NNVerticalStackTableViewCell.swift</code> file.</p>
  
  <p>Code for <code>NNVerticalStackTableViewCell.swift</code> file</p>
  
  <pre><code>class NNVerticalStackTableViewCell: UITableViewCell
  {
      //MARK: Outlets
      @IBOutlet weak var titleLabel: UILabel!
      @IBOutlet weak var verticalStack: NNVerticalStackView!
  
      //MARK: Internal Properties
      var titleString : String?
          {
          set{
              self.titleLabel.text = newValue
          }
          get{
              return self.titleLabel.text
          }
      }
  
      //MARK: View Lifecycle Methods
      override func awakeFromNib()
      {
          super.awakeFromNib()
          self.titleLabel.text = nil
      }
  
      //MARK: Internal Methods
      func addViewsInVerticalStack(viewsArray : [UIView])
      {
          for view in viewsArray
          {
              self.verticalStack.insertStackItem(view)
          }
      }
  }
  </code></pre>
  
  <p>Interface for <code>NNVerticalStackTableViewCell.xib</code> file</p>
  
  <p><a href="https://i.stack.imgur.com/MYXBF.png" rel="noreferrer"><img src="https://i.stack.imgur.com/MYXBF.png" alt="enter image description here"></a></p>
  
  <p>with <code>class name</code> as : <code>NNVerticalStackTableViewCell</code> and <code>cell identifier</code> as : <code>NNVerticalStackTableViewCell</code></p>
  
  <p>Now I created a subclass of <code>NNVerticalStackTableViewCell</code> as:</p>
  
  <pre><code>class NNPropertiesUnderProjectTableViewCell: NNVerticalStackTableViewCell
  {
      //MARK: Internal Properties
      var completionHandler : ((NNSearchPreference) -&gt; Void)?
  
      //MARK: Internal Methods
      func configureCell(_ propertiesUnderProjectArray : [[String : Any]])
      {
          var viewsArray = [UIView]()
          for dict in propertiesUnderProjectArray
          {
              let elementView = NNPropertiesUnderProjectElementView.loadFromNib()
              elementView?.configureViewWith(buttonTitleString: dict["displayString"] as! String, searchPreference: dict["searchPreference"] as! NNSearchPreference, completionHandler: {[weak self] (searchPreference) in
                  if let handler = self?.completionHandler
                  {
                      handler(searchPreference)
                  }
                  })
              viewsArray.addObject(elementView)
          }
          self.addViewsInVerticalStack(viewsArray: viewsArray)
      }
  }
  </code></pre>
  
  <p>Now what I want to do is use <code>NNPropertiesUnderProjectTableViewCell</code> class with <code>NNVerticalStackTableViewCell.xib</code> interface. </p>
  
  <p>Similar to <code>NNPropertiesUnderProjectTableViewCell</code> class I have many other classes that uses the same interface as <code>NNVerticalStackTableViewCell.xib</code> and customize it accordingly.</p>
  
  <p>In my <code>ViewController</code>, I registered <code>NNVerticalStackTableViewCell.xib</code> and then creating the cell as:</p>
  
  <pre><code>self.tableView.register(UINib(nibName: "NNVerticalStackTableViewCell"), forCellReuseIdentifier: "NNVerticalStackTableViewCell")
  
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell
      {
              let propertiesUnderProjectCell = tableView.dequeueReusableCell(withIdentifier: "NNVerticalStackTableViewCell", for: indexPath as IndexPath) as! NNPropertiesUnderProjectTableViewCell
      }
  </code></pre>
  
  <p>But, I am getting the exception : </p>
  
  <pre><code>Could not cast value of type 'NNVerticalStackTableViewCell' (0x100945878) to 'NNPropertiesUnderProjectTableViewCell' (0x100949330).
  </code></pre>
  
  <p>Can anyone please suggest how to solve the problem. I want to use single <code>.xib</code> and do not want to repeat the code.</p>