Crash at runtime when a gesture recognizer action is declared private in Swift

Originator:klaaspieter
Number:rdar://21594714 Date Originated:29-Jun-2015 02:09 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode_6.4_beta_4 (6E31c)
Classification:Serious Bug Reproducible:Always
 
Summary:
When a method, on an Objective-C subclass, is declared private in Swift and used as a gesture recognizer action there is a crash at runtime when the gesture recognizer attempts to call it’s action.

*** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[GestureRecognizers.SwiftGestureRecognizerExampleViewController handleTap:]: unrecognized selector sent to instance 0x7fec3a7ac8b0’

The reason is that, somewhat confusingly, private methods do not have the @objc modifier automatically added. This seems to go against Swift’s ‘designed for safety’ feature. There is no warning, just a crash at runtime.

Steps to Reproduce:
1. Subclass an Objective-C class
2. Create a gesture recognizer, add it to a view. Use the Objective-C subclass as the target and a private method as the action
3. Trigger the gesture at runtime

Expected Results:
No crash would be nice, but even better, and more in line with Swift, would be a compiler warning.

Actual Results:
Crasher and no warning.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!