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:
I wonder if it's worth making #selector(vc.cancel()) work. What do you think, Doug?
-Joe
···
On Mar 22, 2016, at 8:49 PM, Brent Royal-Gordon via swift-evolution <swift-evolution@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.
On Mar 23, 2016, at 10:11, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:
On Mar 22, 2016, at 8:49 PM, Brent Royal-Gordon via swift-evolution <swift-evolution@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:
On Mar 23, 2016, at 10:14 AM, Jordan Rose via swift-evolution <swift-evolution@swift.org> wrote:
On Mar 23, 2016, at 10:11, Joe Groff via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
On Mar 22, 2016, at 8:49 PM, Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@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: