Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: A function with a Selector argument returns an unmanaged<AnyObject>?

Tags:

ios

swift

What is the use of -

func perform(_ aSelector: Selector!) -> unmanaged<AnyObject>!

in iOS?

  • To call a method of a class?
  • To add a selector method?
  • To add a class delegate?
  • To define a class? (I doubt it's this)

I was originally thinking that it it was to add a selector method, but after looking at it some more I think it may be "to call a method of a class." Selectors are used for target/action paradigms where I kick something off and when the event fires or finishes then it wants to fire off some kind of action method. In this example do I pass it a parameter of a selector function then at the end of this "perform" function, I am returning an unmanaged object of any type? Does that even make sense?

Thanks!

like image 976
TSuperman Avatar asked Oct 16 '22 10:10

TSuperman


1 Answers

In Swift this is basically useless. It's bridged from Objective-C, where it used to be very useful (before ARC), but now it's a bit tricky.

The point of it is to send a message by name and get a result. Generally speaking that translates to calling a method of that name.

like image 52
Rob Napier Avatar answered Oct 21 '22 02:10

Rob Napier