[swift-users] Does @IBAction imply @objc?

Sebastian Hagedorn sebastian at iosphere.de
Tue Feb 9 05:24:29 CST 2016

I’m currently migrating some code to the new #selector syntax and came across an issue re: @objc visibility.

I have this method:

@IBAction private func tapGestureRecognized(gesture: UIGestureRecognizer) {…}

…and use this code to set up the recognizer:

let tapSelector = #selector(MyClass.tapGestureRecognized(_:))
let tapGesture = UITapGestureRecognizer(target: self, action: tapSelector)

The previous version with Selector(“…") worked fine. Now that I use #selector, I get this warning:

Argument of '#selector' refers to a method that is not exposed to Objective-C

My understanding was that @IBAction always implied @objc. I can easily fix the warning, either by adding @objc or by removing the private modifier, but I’d like to understand why @objc @IBAction works, but @IBAction does not. I’d like to keep the private modifier. If this is a bug/limitation, I will file a bug report. Just wanted to make sure that I understand it correctly.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160209/47f1e0de/attachment.html>

More information about the swift-users mailing list