I have this separate viewcontroller with identifier MoodController
Now I am using this code to pop it over as a popover
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "MoodController")
controller.modalPresentationStyle = UIModalPresentationStyle.popover
controller.popoverPresentationController!.delegate = self
self.present(controller, animated: true, completion: nil)
But I am getting this error
2018-04-01 19:19:58.558208+0100 PlanTheDay[14910:215426] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController () should have a non-nil sourceView or barButtonItem set before the presentation occurs.'
what is wrong with my code?