Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect IBAction in Xcode

Tags:

When I drag from a button on the storyboard to my view controller Swift file, I only get the option to insert an Outlet or Outlet Collection.

Similarly, if I create the IBAction manually and try to connect it to a button on the storyboard, I can't connect the two.

This problem is only appears in one of my projects, but it happens on all the storyboards in my project.

Seems like an Xcode bug, but maybe someone knows of a workaround.

(It's hard to tell, but the element being dragged in the screenshot is a button.)

enter image description here

like image 992
fedoroffn Avatar asked Feb 26 '15 01:02

fedoroffn


1 Answers

I have very similar issue in my Swift project that was driving me mad.

It turned that's it is the problem of mixing custom protocol adoption in extension of UIButton having @IBInspectable property. More details below.

I finally found out that's because I have following code in my project: (copyright goes to Kevin McNeigh: https://www.iphonelife.com/blog/31369/swift-programming-101-mastering-dynamic-type-ios)

protocol DynamicTypeChangeHandler {

    var typeObserver: Bool {get set}
}

extension UIButton: DynamicTypeChangeHandler {
    @IBInspectable var typeObserver: Bool {
        // ...
    }
}

If I remove either protocol adoption from the extension or @IBInspectable keyword, I can again setup actions in Interface Builder. Sheer lunacy. Xcode <3

like image 164
manicaesar Avatar answered Jan 03 '23 16:01

manicaesar