[swift-evolution] Pitch: Deprecate/remove AnyObject method dispatch

Charles Srstka cocoadev at charlessoft.com
Tue Oct 24 18:05:25 CDT 2017


> On Oct 24, 2017, at 5:02 PM, Slava Pestov via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Thoughts? Does anyone actually rely on this feature, instead of just stumbling on it by accident once in a while?

The main thing I can think of off the top of my head is getting the tag from the sender in an IBAction:

@IBAction private func someAction(_ sender: Any?) {
    guard let tag = (sender as AnyObject?)?.tag as Int? else { return }

    ...
}

Unfortunately given how many unrelated Cocoa objects there are that implement -tag, it’s not really practical to implement this without the AnyObject dispatch. If a TagContaining protocol could be introduced and all the objects that implement -tag could be made to conform to it, then that would work around the problem (I believe I pitched this at some point long ago, but without catching any interest).

Charles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171024/30d7f294/attachment.html>


More information about the swift-evolution mailing list