Can't connect IBAction in Xcode

前端 未结 12 1685

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

12条回答
  •  渐次进展
    2021-02-02 13:08

    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

提交回复
热议问题