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
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
My solution was to delete the UIButton from the .xib file and to add it again. Looks like something strange is happening in the .xib file, readding it should be a quick fix.
You can try to change the @IBAction
's argument from (_ sender: Any)
to (_ sender: UIButton)
or (_ sender: AnyObject)
, but manually.
It might work.
If extension is causing the problem, then instead of directly extending UIButton, user typealias e.g, create extension of CustomButton instead of UIButton
typealias CustomButton = UIButton
extension CustomButton { }
Make sure you select Automatic
.
This bug is indeed super crazy. I lost hours because of it. Until now I found 2 reasons, and I'll post here maybe somebody will read and be helpful:
If anybody is using BonMot pod, this is one possible cause. If you remove it, the IBAction will be back.
Any extension on UIButton or UIBarButtonItem can cause this as well. Comment the extension, and the IBAction will be back. Happy coding.
UPDATE: BonMot fixed this issue in 4.0.2