Xcode 7 Swift 2无法实例化通用UITableViewController的UIViewController子类

Pen*_*agp 6 generics ios swift swift2

我有一个通用类:

class PaginatedTableViewController
  <GenericElement, Source: PaginationDataSource 
     where Source.PaginatedGenericElement == GenericElement>:
  UITableViewController
Run Code Online (Sandbox Code Playgroud)

另一个我试图从故事板中实例化:

class CandidatesTableViewController: 
   PaginatedTableViewController<Match, MatchPaginationDataSource>
Run Code Online (Sandbox Code Playgroud)

CandidatesTableViewController在故事板Custom Class下拉菜单中找不到.如果我强制它然后在代码中转换我的控制器,应用程序在运行时崩溃抱怨我的控制器(应该是CandidatesTableViewController实例)实际上是一个UITableViewController实例.

Interface Builder文件中的未知类_TtC21MyProjectName29CandidatesTableViewController.无法将'UITableViewController'类型的值(0x1040917f8)转换为'MyProjectName.CandidatesTableViewController'(0x1013a9890).

在我的项目中,这个控制器嵌入另一个控制器,这就是我投射它的原因:

tableViewController = (segue.destinationViewController as! CandidatesTableViewController)
Run Code Online (Sandbox Code Playgroud)

有谁知道如何解决这个问题?

wer*_*ver 11

不幸的是,通用Swift类对于Objective-C代码是不可见的,并且在Interface Builder中也不受支持(在故事板和xib中).我发现这两点密切相关.

作为一个解决方案,我建议你使用聚合:不要让你查看控制器通用,但是将一些逻辑提取到另一个(通用)类并在视图控制器中使用它.