IBAction sent 'withSender' and crashing

I've been seeing this the last couple days. I create a new swift class and add some IBActions to it by ctrl-dragging from the storyboard. Say, for example a "print" button. I drag over to the class file and say create an action with sender UIButton and name it 'doPrint'. The function gets created likt this:


@IBAction func doPrint(sender: UIButton) {}


but when I run, it crashes with 'unrecognized selector sent to instance' and the selector it is trying to send is 'doPrintWithSender' which obviously isn't recognized because it isn't called that. All the new button actions have 'WithSender' appended to the name in the inspector and they don't work.

Are you using an older version of Xcode 8 beta?

When I tried the same thing in Xcode 8 beta 6:

I drag over to the class file and say create an action with sender UIButton and name it 'doPrint'.

Xcode generated this:

    @IBAction func doPrint(_ sender: AnyObject) {
    }


When you want to make a method with Objective-C selector "doPrint:", you need to put `_` before the first parameter, in Swift 3.

I'm using beta 6, but have not yet converted to swift 3.

but renaming the darn thing to:

@IBAction func doPrintWithSender(_: UIButton) {


works, so looks like some mismatch between the compiler and the IB auto code

Thanks for reporting. Someone have already reported that Xcode suggested renamed-for-Swift3 methods, in a Legacy Swift project.

Seems many features of Xcode do not work well with Legacy Swift and we may need to fix them manually.

I'm seeing this in the release version of Xcode 8 with a legacy 2.3 project I converted - so it'll likely get fixed in an update.

IBAction sent 'withSender' and crashing
 
 
Q