<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class="">What I’m wondering is what you’re actually using this all for.</blockquote></div><div class=""><br class=""></div><div class="">For example, when testing with Quick (popular testing framework), one can describe a function:</div><div class=""><br class=""></div><div class="">describe(“player.play()”) {</div><div class="">&nbsp; &nbsp; ...</div><div class="">}</div><div class=""><br class=""></div><div class="">If #function worked like #selector, we could do:</div><div class=""><br class=""></div><div class="">describe(#function(Player.play())) {</div><div class="">&nbsp; &nbsp; ...</div><div class="">}</div><div class=""><br class=""></div><div class="">This would be safe and refactoring friendly.</div><div class=""><br class=""></div><div class="">P.S. I could do this with #selector but that would require @objc/dynamic which is not ideal.</div><div class=""><br class=""></div><div class="">R+</div><br class=""><div><blockquote type="cite" class=""><div class="">On 15 Nov 2016, at 18:02, Jordan Rose &lt;<a href="mailto:jordan_rose@apple.com" class="">jordan_rose@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Sorry, I see that #function doesn’t work as a drop-in replacement for #selector. What I’m wondering is what you’re actually using this all for. It seems rare to have a dictionary keyed by the name of a function (but not its arguments) and rarer still to need to prepopulate that dictionary. The only use case I can think of is some generalized mock object, but even then I wonder how useful it is in practice.</div><div class=""><br class=""></div><div class="">(Per the original request, remember too that many Swift methods do not <i class="">have</i>&nbsp;selectors, since they are not exposed to Objective-C.)</div><div class=""><br class=""></div><div class="">Jordan</div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Nov 15, 2016, at 03:47, Rudolf Adamkovič &lt;<a href="mailto:salutis@me.com" class="">salutis@me.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hi Jordan,<br class=""><br class=""><blockquote type="cite" class="">The stripped-down code seems like it could use any unique key, including #function.<br class=""></blockquote><br class=""><br class="">That would work only if #function could be used with an argument just like #selector:<br class=""><br class="">class DirectoryListingStub: DirectoryListing {<br class=""><br class=""> &nbsp;&nbsp;var cannedOutput: [Selector: Any?] = [<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#function(contentsOfDirectory(at:includingPropertiesForKeys:options:)): nil<br class=""> &nbsp;&nbsp;]<br class=""><br class=""> &nbsp;&nbsp;func contentsOfDirectory(at url: URL, includingPropertiesForKeys keys: [URLResourceKey]?, options: FileManager.DirectoryEnumerationOptions) throws -&gt; [URL] {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return cannedOutput[#function] as! [URL]<br class=""> &nbsp;&nbsp;}<br class=""><br class="">}<br class=""><br class="">Obviously, this doesn’t work as #function takes no arguments.<br class=""><br class="">There's no way to get #selector for the current method. And there’s no way to get #function for arbitrary method.<br class=""><br class="">R+<br class=""><br class=""><blockquote type="cite" class="">On 14 Nov 2016, at 20:07, Jordan Rose &lt;<a href="mailto:jordan_rose@apple.com" class="">jordan_rose@apple.com</a>&gt; wrote:<br class=""><br class="">This doesn’t seem unreasonable, but I’m not sure if that makes it reasonable. :-) What’s your use case? The stripped-down code seems like it could use any unique key, including #function.<br class=""><br class="">Jordan<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Nov 13, 2016, at 15:50, Rudolf Adamkovič via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">Hi there!<br class=""><br class="">in Swift 3, we now have #selector and #keyPath yet there’s still no _cmd like we have in Objective-C.<br class=""><br class="">Example:<br class=""><br class="">class DirectoryListingStub: DirectoryListing {<br class=""><br class=""> &nbsp;var cannedOutput: [Selector: Any?] = [<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#selector(contentsOfDirectory(at:includingPropertiesForKeys:options:)): nil<br class=""> &nbsp;]<br class=""><br class=""> &nbsp;dynamic func contentsOfDirectory(at url: URL, includingPropertiesForKeys keys: [URLResourceKey]?, options: FileManager.DirectoryEnumerationOptions) throws -&gt; [URL] {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let selector = #selector(contentsOfDirectory(at:includingPropertiesForKeys:options:))<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return cannedOutput[selector] as! &nbsp;[URL]<br class=""> &nbsp;}<br class=""><br class="">}<br class=""><br class="">Problem: I had to specify #selector twice.<br class=""><br class="">I though I’d be able to use #function but:<br class=""><br class="">#selector = contentsOfDirectoryAt:includingPropertiesForKeys:options:error:<br class="">#function = contentsOfDirectory(at:includingPropertiesForKeys:options:)<br class=""><br class="">It’d be great if #selector (without arguments) returned the current selector.<br class=""><br class="">Or am I missing something?<br class=""><br class="">R+<br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote><br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></body></html>