[swift-users] Swift 3 likes to tease me

Jacob Bandes-Storch jtbandes at gmail.com
Fri Sep 23 02:19:59 CDT 2016


Once you've determined this object responds to the selector, how do you
intend to use it?

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".

What are you trying to do exactly?

Jacob

On Thu, Sep 22, 2016 at 11:57 PM, Gerriet M. Denkmann <g at mdenkmann.de>
wrote:

>
> > On 23 Sep 2016, at 12:09, Marco S Hyman <marc at snafu.org> wrote:
> >
> > On Sep 22, 2016, at 9:51 PM, Gerriet M. Denkmann via swift-users <
> swift-users at swift.org> wrote:
> >>
> >> This line (Swift 3):
> >>      if a.responds(to: Selector(“viewControllers") )
> >> creates this warning: Use '#selector' instead of explicitly
> constructing a 'Selector'
> >>
> >> Ok. Following this advice I change it to:
> >>      if a.responds(to: #selector(“viewControllers”))
> >
> > #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.
> >
> > You might need the class name, too, e.g. #selector(MyClass.
> viewControllers)
>
> This might be difficult. viewControllers is a property used in several
> classes, e.g. UIPageViewController, UISplitViewController, etc.
>
> Xcode has just given me a new suggestion (probably it noticed that I was
> not quite happy with its former hint):
>         if a.responds(to: #selector(getter: UINavigationController.
> viewControllers))
> but I do not want to be restricted to this special class.
> My a is AnyObject and should be treated as such.
>
> Kind regards,
>
> Gerriet.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160923/a52111b8/attachment.html>


More information about the swift-users mailing list