Custom UITableViewCelll class as nested type?

Is it possible to use a custom UITableViewCell class as a nested type of the corresponding view controller? It seems like this would be a nice way to contain custom cell types.


class MyTableViewController: UITableViewController {
     override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
          let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! MyTableViewController.Cell
          cell.configure()
          return cell
     }

     class Cell: UITableViewCell {
          func configure() {
          }
     }
}


And more importantly, is it possible to use such a nested type with prototype cells in a storyboard? From what I can tell with the lastest Xcode 7 beta (beta 4), it doesn't look like this is possible. Should I file a radar?


Thanks.

is it possible to use such a nested type with prototype cells in a storyboard? From what I can tell with the lastest Xcode 7 beta (beta 4), it doesn't look like this is possible.

Storyboard uses Objective-C runtime to instatiate objects registered in a storyboard. And Objective-C runtime cannot handle nested types.

Try putting @objc to the nested class and give it an Objective-C name.

    @objc(Cell) class Cell: UITableViewCell {

Interesting. Ok, so that kind of works:


class MyTableViewController: UITableViewController {
     ...
     @objc(MyTableViewController) class Cell: UITableViewCell {
          @IBOutlet var label: UILabel!
          ...
     }
}


and then in Interface Builder, I set the cell class type to MyTableViewControllerCell. And this works. The cell is properly instatiated from the prototype. However, Interface Builder isn't able to recognize the IBOutlets for this class and throws a warning. But if I let the existing IBOutlets in place without recreating or deleting them, then they actually work as well. Very strange.

Custom UITableViewCelll class as nested type?
 
 
Q