在 Swift 检查 UIContentContainer 是否为 ViewContoller

Check if UIContentContainer is ViewContoller in Swift

我正在将 Apple 的示例 Custom View Controller Presentations and Transitions(特别是 AAPLCustomPresentationController)翻译成 Swift,但我遇到了一个问题。

在他们的 preferredContentSizeDidChangeForChildContentContainer 方法(第 190 行)中,他们检查

- (void)preferredContentSizeDidChangeForChildContentContainer:(id<UIContentContainer>)container
{
    [super preferredContentSizeDidChangeForChildContentContainer:container];

    if (container == self.presentedViewController)
        [self.containerView setNeedsLayout];
}

在Swift (3.0)中,我试过

if container == (self.presentedViewController as UIContentContainer) 

但我收到错误

Binary operator '==' cannot be applied to two 'UIContentContainer' operands

如何在 Swift 中执行此检查?

如果两个对象都是 UIViewController,是否可以在比较之前将它们转换为该类型?

if presentedViewController as? UIViewController == container as? UIViewController {
    // true
}