In my Swift 3/Obj-C application, I'm trying to set the delegate of my rootviewcontroller to its navigation controller but am getting the following error:
Cannot assign value of type 'NavController.Type' to type 'RootViewControllerDelegate'
NavController.swift
@available(iOS 10.0, *)
@objc class NavController: UINavigationController, RootViewControllerDelegate {
static func instantiate() -> NavController? {
let storyboard = UIStoryboard.init(name: "MyStoryboard", bundle: nil)
let navVC = storyboard.instantiateViewController(withIdentifier: "NavController") as? NavController
let rootVC = navVC?.viewControllers.first as! RootViewController
rootVC.delegate = self // <<<< ERROR OCCURS HERE
return navVC
}
func pressedNextButton()
{
NSLog("Next button works!")
}
}
RootViewController.swift
@objc protocol RootViewControllerDelegate {
func pressedNextButton()
}
@available(iOS 10.0, *)
@objc class RootViewController: UIViewController, NSFetchedResultsControllerDelegate, UITableViewDataSource, UITableViewDelegate {
var delegate: RootViewControllerDelegate?
@IBAction func nextButton(_ sender: UIBarButtonItem) {
self.delegate?.pressedNextButton()
}
}
MainProgram.m
@interface MYQAddDeviceViewController ()
@property (nonatomic, strong) NavController * navVC;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
self.navVC = [NavController instantiate];
}
Any ideas on how I can resolve that error?