[swift-users] #selector() in Swift

Mohit Athwani mohit.athwani at gmail.com
Thu Aug 10 01:04:13 CDT 2017


With closures being first class citizens in Swift and the ability of
closures to be able to capture scope, it seems a little archaic to me that
the #selector() feature exists in Swift.

For example, why does
func addTarget(_ target: Any?, action: Selector
<https://developer.apple.com/documentation/objectivec/selector>, for
controlEvents: UIControlEvents
<https://developer.apple.com/documentation/uikit/uicontrolevents>)



have a Selector type for action. Why can’t action be defined to be a
closure  for example:
addTarget(_ target: Any?, action: (sender: UIControl?, forEvent
event:UIEvent?) -> Void, for controlEvents: UIControlEvents
<https://developer.apple.com/documentation/uikit/uicontrolevents>)

What do you guys think?

Cheers!

Mohit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170810/3d7563b4/attachment.html>


More information about the swift-users mailing list