In Xcode 8, can't connect to IBAction functions defined in Swift extensions

For some reason, in Swift 3 and Xcode 8, we're finding you can no longer connect views on Interface Builder storyboards e.g. UIButtons to IBAction functions when those functions defined in extensions. This has worked fine in previous versions of Xcode. As a concrete example...


The following code is fine:


class MyViewController: UIViewController {
  
    @IBAction func myButtonTapped() {
        // Do stuff when button tapped
    }
  
}



However, in Xcode 8, this code won't allow connecitons to be made from Interface Builder:


class MyViewController: UIViewController {
   
   
}
extension MyViewController {
   @IBAction func myButtonTapped() {
        // Do stuff when button tapped
    }
}


As I say, this has worked fine in previous versions of Xcode. Is this new behaviour expected in Swift 3 / Xcode 8, or is it a bug?

Replies

I'm having the same problem on macOS, IBActions won't connect, except I'm simply using NSViewController subclasses. Very frustrating.

>This has worked fine in previous versions of Xcode.


Seems there are new bugs...try the latest beta, instead - see if it helps.

This problem still exists in Xcode 8.1.

This is happening for me as well in Xcode 8.2.1.


Temporarily resolved by:

  1. Commenting out all extensions I had on the control element, in my case UIButton.
  2. Connecting the IBAction as per expected from the storyboard.
  3. Undoing step 1.


http://stackoverflow.com/questions/28732903/cant-connect-ibaction-in-xcode

Hello. I am experiencing the same issue in XCode 8 / iOS 10. Any fix in-sight? Is this a problem on the XCode side or the Cocoapod libraries writing the extensions?


Also, is there a known Apple bug filed with this to follow?

Still an issue in XCode Version 8.2 (8C38)

And looks like they did not fix it in this week's XCode 8.3 release. Lame.