2

i have protocol class named MenuDisplayable. This protocol has an extension.

protocol MenuDisplayable {}

extension MenuDisplayable where Self: UIViewController {

func showMenu( ) {
  let storyboard = UIStoryboard(storyboard: .Menu)
   let menuVC = storyboard.instantiateInitialViewController() as! MenuVC
   present(menuVC, animated: true, completion: nil)
 }

}

When i call "showMenu" function from #selector inside viewController class

let rightButton = UIBarButtonItem(image: #imageLiteral(resourceName: "icon_hamb").withRenderingMode(.alwaysTemplate), style: .plain, target: self, action: #selector(StorySelectCarouselVC.showMenu) )

i get an error like "Argument of '#selector' refers to instance method 'showMenu()' that is not exposed to Objective-C"

1 Answers1

0

You need to declare your showMenu method accessible to Objective-C by prefixing it with the objc attribute.

@objc func showMenu() {
    // ...
}
hoshy
  • 481
  • 6
  • 15
  • When i add "@objc" prefix, i am getting the error below "@objc" can only be used with members of classes, "@objc" protocols, and concrete extensions of classes – Murat Yılmaz Feb 02 '17 at 19:10