On 14 Nov 2016, at 01:01, Robert Widmann <[email protected]> wrote:
> 
> NSSelectorFromString(#function) works just fine for this already.

Hi Robert,

it doesn’t work.

NSSelectorFromString(#function)
… returns "contentsOfDirectory(at:includingPropertiesForKeys:options:)"

#selector(DirectoryListingMock.contentsOfDirectory(at:includingPropertiesForKeys:options:))
… returns "contentsOfDirectoryAt:includingPropertiesForKeys:options:error:"

In other words, "NSSelectorFromString(#function)” returns Swift function name, 
not selector like _cmd or #selector does.

R+

> 
>> On Nov 13, 2016, at 6:50 PM, Rudolf Adamkovič via swift-evolution 
>> <[email protected]> wrote:
>> 
>> Hi there!
>> 
>> in Swift 3, we now have #selector and #keyPath yet there’s still no _cmd 
>> like we have in Objective-C.
>> 
>> Example:
>> 
>> class DirectoryListingStub: DirectoryListing {
>> 
>>   var cannedOutput: [Selector: Any?] = [
>>       
>> #selector(contentsOfDirectory(at:includingPropertiesForKeys:options:)): nil
>>   ]
>> 
>>   dynamic func contentsOfDirectory(at url: URL, includingPropertiesForKeys 
>> keys: [URLResourceKey]?, options: FileManager.DirectoryEnumerationOptions) 
>> throws -> [URL] {
>>       let selector = 
>> #selector(contentsOfDirectory(at:includingPropertiesForKeys:options:))
>>       return cannedOutput[selector] as!  [URL]
>>   }
>> 
>> }
>> 
>> Problem: I had to specify #selector twice.
>> 
>> I though I’d be able to use #function but:
>> 
>> #selector = contentsOfDirectoryAt:includingPropertiesForKeys:options:error:
>> #function = contentsOfDirectory(at:includingPropertiesForKeys:options:)
>> 
>> It’d be great if #selector (without arguments) returned the current selector.
>> 
>> Or am I missing something?
>> 
>> R+
>> _______________________________________________
>> swift-evolution mailing list
>> [email protected]
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to