引用子视图控制器时对成员 'first(where:)' 的错误引用不明确

Ambiguous reference to member 'first(where:)' error when referencing child view controller

我正在编写一个 iOS 应用程序,并且有一个我试图引用的子视图控制器。子视图控制器是父视图控制器的委托。

在父视图控制器的顶部,我有:fileprivate var cameraViewController: CameraViewController<AnyObject>?

viewDidLoad()中,我有

guard let cameraController = childViewControllers.first as? CameraViewController else  {
            fatalError("Check storyboard for missing CameraViewController")
        }

        cameraViewController = cameraController

但是,我收到错误消息:Ambiguous reference to member 'first(where:)'

任何人都可以向我解释为什么会这样吗?我只有一个父级的子视图控制器。

无法重现。这是我应用程序的单一视图控制器文件中的完整代码:

import UIKit
class CameraViewController : UIViewController {}
class ViewController: UIViewController {
    fileprivate var cameraViewController: CameraViewController?
    override func viewDidLoad() {
        super.viewDidLoad()
        guard let cameraController = childViewControllers.first as? CameraViewController else  {
            fatalError("Check storyboard for missing CameraViewController")
        }
        cameraViewController = cameraController
    }
}

它编译得很好。

CameraViewController 需要在任何地方都相同。当我将 cameraViewController 实例化为 CameraViewController 时,需要在代码的第二部分中反映出来。第二部分应如下所示:

guard let cameraController = childViewControllers.first as? CameraViewController<AnyObject> else  {
            fatalError("Check storyboard for missing CameraViewController")
        }

        cameraViewController = cameraController