-2

I am writing an iOS application and have a child view controller that I am trying to reference. The child view controller is the delegate of the parent.

At the top of the parent view controller, I have: fileprivate var cameraViewController: CameraViewController<AnyObject>?

In viewDidLoad(), I have

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

        cameraViewController = cameraController

However, I'm getting the error: Ambiguous reference to member 'first(where:)'

Can anyone explain to me why this is happening? I only have one child view controller for the parent.

jordan
  • 69
  • 6

2 Answers2

0

Can't reproduce. This is the entire code in my app's single view controller file:

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
    }
}

It compiles just fine.

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

CameraViewController needs to be the same everywhere. When I instantiated cameraViewController as a CameraViewController, that needed to be reflected in the second part of the code. The second part should look like this:

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

        cameraViewController = cameraController
jordan
  • 69
  • 6