Search code examples
iosswiftuibuttonswift3xcode8

Xcode8 cannot connect multiple/single uibuttons to single @IBAction in swift file


I am using Xcode 8 beta. I cannot drag multiple UIButtons from storyboard to connect to a single @IBAction in swift file. Bug? Thanks for your help.


Solution

  • By Using this workaround you can add existing action and also can connect multiple buttons to a single action.

    I think there is a bug in Xcode8. You can add multiple/Single button to a single action /function by changing sender to _ sender

    eg :- Normal Button

       @IBAction func huu(sender: UIButton) {
    
       }
    

    You can't add multiple buttons or single button to this action you need to simply change like this and then you can add multiple buttons by using drag and connect from storyboard.

     @IBAction func huu(_ sender: UIButton) {
    
     }
    

    After connecting IBOutlets Xcode will show a warning like this :-

    enter image description here

    To remove this warning simple delete _ sign from the action/function. Make sure that to delete _ after connecting your IBOutlets

    Hope that this will gonna help you! :)