0

I am running an XCTest where I am trying to instantiate a UINavigationController as the initialViewController but it is giving me the following error:

Could not cast value of type 'ToDo.ItemListViewController' (0x10cce7208) to 'UINavigationController' (0x10f93ced8)

The ItemListViewController is embedded within the Navigation Controller, and "Is Initial View Controller" is selected for the Navigation Controller. This is exactly how I'm instructed to do this by a tutorial... perhaps I have another setting interfering? Here is my code

func test_InitialViewController_IsItemListViewController() {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let navigationController =
        storyboard.instantiateInitialViewController() as! UINavigationController
    let rootViewController = navigationController.viewControllers[0]
    XCTAssertTrue(rootViewController is ItemListViewController)
}

Screenshot for reference:

enter image description here

Pigpocket
  • 449
  • 5
  • 24

0 Answers0