Can't drag button action to existing function in Xcode 8

12,362

Solution 1

To fix it, I had to update my project language to Swift 3.0 from Swift 2.3

Solution 2

In my Xcode version, IBAction is created automatically with "Any" parameter, instead of "AnyObject". Creating IBAction explicitly with UIButton instead worked for me.

Solution 3

In my case, you will need to change Any to UIButton. It need to be specific that the action coming from UIButton.

@IBAction func buttonClicked(_ sender: UIButton) {

}

Solution 4

Click on the UIButton, then go to "Connections Inspector" from Utilities area.

Click on the empty circle beside the event and drag the line into func body.

Solution 5

right click with open button function in select touchup inside to drag ..u should try this..

Share:
12,362

Related videos on Youtube

Jarosław Krajewski
Author by

Jarosław Krajewski

Updated on July 22, 2020

Comments

  • Jarosław Krajewski
    Jarosław Krajewski almost 4 years

    I have a weird issue with Xcode 8. When I try to ctrl + drag button to existing function, I can't I can only create new outlet or Action. What is more weird, that even when I create action by ctrl + drag i can't connect event the same button that I used for creating action. IB icon is also blank like there is no connection between action and button, but real time clicking runs action. On the other hand when I try to connect action to button from swift to storyboard I can (@IB icon becomes "full"), but then I get exception on real time clicking unrecognized selector myActionWithSender enter image description here enter image description here

  • briggsm
    briggsm over 7 years
    Strange observance: if I use an underscore '_' I can drag from IB to the function name in code, and it highlights the entire function - and it makes the connection. However, if I use 'z' or any other alphanumeric label, I cannot drag from IB to the function name. Weird.
  • Scooter
    Scooter over 7 years
    This was my solution as well. You can also manually change Any to AnyObject it the existing code and it works as advertised. Why does Xcode default to Any? Thanks for this solution!