<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On 10 Aug 2017, at 07:04, Mohit Athwani via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">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. </div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">For example, why does</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class=""><span class="syntax-keyword" style="box-sizing: inherit; color: rgb(170, 13, 145); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">func</span><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class=""> </span><span class="syntax-identifier" style="box-sizing: inherit; font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">addTarget</span><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class="">(</span><span class="syntax-identifier" style="box-sizing: inherit; font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">_</span><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class=""> </span><span class="syntax-param-name" style="box-sizing: inherit; color: rgb(64, 64, 64); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">target</span><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class="">: Any?, </span><span class="syntax-identifier" style="box-sizing: inherit; font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">
action</span><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class="">: </span><a class="symbolref" href="https://developer.apple.com/documentation/objectivec/selector" style="box-sizing: inherit; color: rgb(92, 38, 153); text-decoration: none; font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">Selector</a><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class="">, </span><span class="syntax-identifier" style="box-sizing: inherit; font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">
for</span><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class=""> </span><span class="syntax-param-name" style="box-sizing: inherit; color: rgb(64, 64, 64); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">controlEvents</span><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class="">: </span><a class="symbolref" href="https://developer.apple.com/documentation/uikit/uicontrolevents" style="box-sizing: inherit; color: rgb(92, 38, 153); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">UIControlEvents</a><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class="">)</span></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class=""><br class=""></div><div class="bloop_sign" id="bloop_sign_1502344699995815936" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">have a Selector type for action. Why can’t action be defined to be a closure for example:</div><div class="bloop_sign" id="bloop_sign_1502344699995815936" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="syntax-identifier" style="box-sizing: inherit; font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">addTarget</span><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class="">(</span><span class="syntax-identifier" style="box-sizing: inherit; font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">_</span><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class=""> </span><span class="syntax-param-name" style="box-sizing: inherit; color: rgb(64, 64, 64); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">target</span><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class="">: Any?, </span><span class="syntax-identifier" style="box-sizing: inherit; font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">
action</span><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class="">: </span><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(255, 255, 255);" class="">(sender: UIControl?, forEvent event:UIEvent?) -> Void,</span><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class=""> </span><span class="syntax-identifier" style="box-sizing: inherit; font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">
for</span><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class=""> </span><span class="syntax-param-name" style="box-sizing: inherit; color: rgb(64, 64, 64); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">controlEvents</span><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class="">: </span><a class="symbolref" href="https://developer.apple.com/documentation/uikit/uicontrolevents" style="box-sizing: inherit; color: rgb(92, 38, 153); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre;">UIControlEvents</a><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class="">)</span></div><div class="bloop_sign" id="bloop_sign_1502344699995815936" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="color: rgb(51, 51, 51); font-family: "SF Mono", Menlo, monospace, "SF Pro Icons"; font-size: 15px; letter-spacing: -0.4050000011920929px; white-space: pre; background-color: rgb(249, 250, 250);" class=""><br class=""></span></div><div class="bloop_sign" id="bloop_sign_1502344699995815936" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">What do you guys think?</div></div></blockquote><br class=""></div><div>Selectors have been around since the start of the Objective-C platform, before either macOS or iOS existed. Blocks weren't added into macOS until relatively recently (from iOS 4 <a href="https://en.wikipedia.org/wiki/Blocks_(C_language_extension)" class="">https://en.wikipedia.org/wiki/Blocks_(C_language_extension)</a> if you're interested).</div><div><br class=""></div><div>So many of the APIs that predated the introduction of blocks worked by having a selector that could be called back on a target, and these APIs are still present today in current releases of macOS and iOS.</div><div><br class=""></div><div>The Swift based API is purely there because there are some APIs that aren't capable of taking a block, and hence aren't capable of taking a Swift closure.</div><div><br class=""></div><div>Alex</div><br class=""></body></html>