How to handle click event of BackBarButtonItem in nav bar using SWIFT?
<p>I tried to handle an action when <strong>navigation bar back button</strong> is pressed. Yet I have set segue for it for another viewController.</p>

<p>Though I need to maintain a <strong>count</strong> when user clicks <strong>5</strong> times back button. For this I have implemented this stuff.</p>

<p>In this I've set an action for navigationbar backbutton:</p>

<pre><code>class DetailViewController:UIViewController, UITabBarDelegate, UINavigationControllerDelegate{
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationItem.backBarButtonItem?.action = "perform"
        self.navigationController?.delegate = self
    }

    func perform(){
        if count == 5{
            count=0
            print("Back Button pressed 5 times")
        }
    }
}
</code></pre>

<p>Where did I make a mistake?</p>