chirag shah chirag shah - 2 months ago 24
iOS Question

in swift 3 on button click application is crash

I have developed one project in Swift 2.2 and after Swift 3 launch I need to convert it in Swift 3 and make compilable with iOS 10. But after converting the project i face some issue like when I clicked on button which connected with storyboard my application is crash with give reason unrecognized selector sent to instance . It is working in swift 2.2 and i have not change any thing.

@IBAction func btnTwitter_Clicked(sender:UIButton)
{
if checkInternetConnection()
{
SINGLETON.startLoadingActivity(self.view);
let objLocationTracker = LocationTracker.sharedInstance
objLocationTracker.fetchCurrentLocation({ (objLocation) -> (Void) in
SINGLETON.stopLoadingActivity(self.view)
self.loginWithTwitter(objLocation: objLocation)
})
}
else
{
SINGLETON.toast(read_Localizable("noInternet"),view: self.view)
}
}

Answer

see this

@@IBAction func btnTwitter_Clicked(sender:UIButton) you were added the additional @ in front of your button, check once ,

in swift3 we need to write the button action like

yourbuttonName.addTarget(self, action: #selector(yourVCName. btnTwitter_Clicked(_:)), for: .touchUpInside)

and call method as like

@IBAction func btnTwitter_Clicked(_ sender: UIButton){
   print("Button pressed