[swift-evolution] #selector and Void methods
Jordan Rose
jordan_rose at apple.com
Wed Mar 23 12:14:39 CDT 2016
> On Mar 23, 2016, at 10:11, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
>
>>
>> On Mar 22, 2016, at 8:49 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>>
>> So, today is day 2 of Swift 2.2 being in the hands of mere mortals. This evening, I walked into my weekly NSCoder Night meeting and talked to a pretty experienced developer struggling with this:
>>
>> class EditEventViewController: UIViewController {
>> ...
>> @IBAction func cancel(sender: AnyObject?) {
>> cancel()
>> }
>> func cancel() {
>> // actual canceling logic is here
>> }
>> }
>>
>> class EditEventContainerViewController: UIViewController {
>> ...
>> func prepareForSegue(_ segue: UIStoryboardSegue, sender sender: AnyObject?) {
>> switch segue.identifier {
>> ...
>> let cancelButton = UIBarButtonItem(barButtonSystemItem: .Cancel, target: nil, action: nil)
>> cancelButton.target = vc
>> cancelButton.action = #selector(vc.cancel) // This is the problem line
>> ...
>> }
>> }
>> }
>>
>> `vc.cancel` was, of course, ambiguous, and the SE-0021 `vc.cancel(_:)` syntax can't select a Void function. I had to explain how to use `as Void -> Void` to select the right version.
>>
>> This is merely an anecdote, but I think it may end up being an issue.
>
> Thanks for reporting this. I also saw this come up at least one other place:
>
> https://twitter.com/bendodson/status/712208662933200896 <https://twitter.com/bendodson/status/712208662933200896>
>
> I wonder if it's worth making #selector(vc.cancel()) work. What do you think, Doug?
Very strong +1; I consider it a bug that we didn't have this already. It was reported as SR-1016 <https://bugs.swift.org/browse/SR-1016>.
Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160323/7e07999c/attachment.html>
More information about the swift-evolution
mailing list