PJeremyMalouf PJeremyMalouf - 1 month ago 15
Swift Question

Swift 3 (Omit Needless Words) causing two functions to have the same name

In Swift 3.0, the automated changing of function names due to the "Omit Needless Words" rule has caused two functions in an ObjC class to be the same.

- (void)showLoader;


...and...

- (void)show __deprecated_msg("User 'showLoader'");


The problem is that these functions are within a third party Cocoa Pod (otherwise I would just delete the unnecessary 'show' function).

This results in getting the error "Ambiguous use of 'show'" when I try to invoke the function like this:

loader?.show()


Is there a way to reverse the automatic changing of function name in Swift 3.0 or to help the compiler know which function I want to invoke?

Thanks for your help!

Answer

You can work around this by calling

loader?.perform(Selector("showLoader"))

You will see a warning from the compiler, but it will compile successfully, and things will work correctly at runtime.

Comments