I am quite new in iOS development and looking for your advice.
I am looking at one project at GitHub.
I would like to add some functionality. I would like to add a button which will show SideMenu and possibly hide it.
The sideMenu is an instance of class SideMenu and it is created in ViewDidLoad method. How to call sideMenu.toggleMenu(true) method using button's action method.
class HomeViewController: UIViewController, SideMenuDelegate {
@IBAction func menuButtonTapped(_ sender: Any) {
sideMenu.toggleMenu(open: true)
}
override func viewDidLoad() {
super.viewDidLoad()
let sideMenu = SideMenu(menuWidth: 200 , menuItemTitles: ["", "", "Profile", "Settings", "Restaurant"], parentViewController: vviewController)
sideMenu.menuDelegate = self
}
My button is created using storyboard that is why I can't add it is action method into viewDidLoad.
Theoretically I could create button programmatically in ViewDidLoad. Is it the only solution?

The problem is nothing that do with your button or where you declare it.
sideMenuin your code is a constant ofviewDidLoadand not accessible to theIBAction.Move your definition of
sideMenuoutside of the method and make it optional:In
viewDidLoadset it as you currently are (remove the let)In the
IBAction, unwrap the optional to use it:See vacawama's comments for alternatives.