具有 NSBundle(forClass:) 和多类型约束(协议 + class)的段错误 11

Segfault 11 with NSBundle(forClass:) and multiple type constraint (protocol + class)

以下代码在模拟器中运行良好,但在创建存档时抛出“Command failed du to signal: Segmentation fault: 11”。

func popAction() {
  MyViewController.pop(self)
}

class func pop<T where T : MyActionDelegate, T : UIViewController>(controller: T) {
   let bundle = NSBundle(forClass: controller.dynamicType)
   // …
}

以下编译正常:

let bundle = NSBundle(forClass: object_getClass(self))
// or
let bundle = NSBundle(forClass: self)

dynamicType 似乎在类型组合(协议和 class)方面存在问题。

我想这在调试模式下工作而不在发布模式下工作的原因在于编译期间执行的优化。

谁能告诉我更多关于为什么它在一种情况下有效而在另一种情况下无效的原因?

谢谢

即使启用了优化,这对我也有效:

func popAction() {
    MyViewController.pop(self)
}

class func pop<T where T : MyActionDelegate, T : UIViewController>(controller: T) {
    let bundle = NSBundle(forClass: (controller as UIViewController).dynamicType)
    // …
}