<div dir="ltr">Once you've determined this object responds to the selector, how do you intend to use it?<div><br></div><div>It's probably best to define your own protocol that has the requirement, and then you can access it via the protocol. In fact, at that point you might even be able to use "as?" rather than "respondsToSelector".</div><div><br></div><div>What are you trying to do exactly?</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Jacob<br></div></div></div></div>
<br><div class="gmail_quote">On Thu, Sep 22, 2016 at 11:57 PM, Gerriet M. Denkmann <span dir="ltr"><<a href="mailto:g@mdenkmann.de" target="_blank">g@mdenkmann.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> On 23 Sep 2016, at 12:09, Marco S Hyman <<a href="mailto:marc@snafu.org">marc@snafu.org</a>> wrote:<br>
<span class="">><br>
> On Sep 22, 2016, at 9:51 PM, Gerriet M. Denkmann via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br>
>><br>
>> This line (Swift 3):<br>
>> if a.responds(to: Selector(“viewControllers") )<br>
>> creates this warning: Use '#selector' instead of explicitly constructing a 'Selector'<br>
>><br>
>> Ok. Following this advice I change it to:<br>
>> if a.responds(to: #selector(“viewControllers”))<br>
><br>
</span>> #selector does not take a string. It takes a method name. This is required as the name needs to be mangled/demangled in the conversion between obj-c and swift.<br>
><br>
> You might need the class name, too, e.g. #selector(MyClass.<wbr>viewControllers)<br>
<br>
This might be difficult. viewControllers is a property used in several classes, e.g. UIPageViewController, UISplitViewController, etc.<br>
<br>
Xcode has just given me a new suggestion (probably it noticed that I was not quite happy with its former hint):<br>
if a.responds(to: #selector(getter: UINavigationController.<wbr>viewControllers))<br>
but I do not want to be restricted to this special class.<br>
My a is AnyObject and should be treated as such.<br>
<br>
Kind regards,<br>
<br>
Gerriet.<br>
<br>
<br>
</blockquote></div><br></div></div>