How to Emulate Double Dispatch in Objective-C

168 Views Asked by At

I'm, trying to emulate a Double Dispatch in Objective-C.

I know Objective-C does not support function/method overloading. But can you emulate this?

Any idea.

2

There are 2 best solutions below

1
On BEST ANSWER

In this repo give an example of how to Implement Double Dispatch in Objective-C

2
On

You can do it as in C++/C# with 2 single dispatches (aka "visitor" pattern, see https://en.wikipedia.org/wiki/Double_dispatch#Double_dispatch_in_C++ ).

Or you can do it manually with some runtime type checking on the argument (see isMemberOfClass).