Adding a Swift protocol to UIButton breaks Interface Builder action options.

Before I go and log this...Is this a bug or a feature I haven't heard of yet?


Grab an iOS project. Any project. Add some code that adds a protocol to UIButton. This will do:


protocol Foobar {
}
extension UIButton : Foobar {
}


Open the project's nib/storyboard and add a UIButton.

Try to add an action (using any method IB supports) to the button. Action options are unavaliable.


If you right-click an exisiting UIButton with an action attached you'll see a little warning icon next to the action. If you hover your mouse pointer over the warning icon you'll get a tooltip which reads: 'UIButton is no longer a valid event source'.

If you comment out those lines that add the protocol your action options will return to IB and the warnings will disappear.


I haven't tried an OS X app yet.


This is a bug right?


Happends in Xcode 7.1 and 7.2 beta (7C46l).

Replies

I ran into this too. Filed rdar://23412875.

rdar://23456742

duplicate of rdar://17023935

Also ran into this with Xcode 7.2.1 (7C1002)

Still present in 7.3 (7D175)

Still present in Version 8.1 (8B62)

still present in Version 8.2.1

A workaround you could try is to extend UIControl with the protocol. UIControl is the superclass of UIButton, so extensions to UIControl are inherited by UIButton, and Xcode doesn't seem to be upset when a protocol is adopted by UIControl.


protocol Foobar {
}
extension UIControl : Foobar {
}

Appears to be fixed in Xcode9b4