PJeremyMalouf
PJeremyMalouf

Reputation: 613

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!

Upvotes: 2

Views: 372

Answers (2)

Ethan G
Ethan G

Reputation: 1477

See MartinR's answer to my similar question here: Converting to Swift 3 renamed my own Objective-C method

If you owned the code, you could use NS_SWIFT_NAME(showLoader()) after your method declaration to force the ObjC-to-Swift method conversion to be named what you want:

- (void)showLoader NS_SWIFT_NAME(showLoader());

I think it's worth mentioning even though in your case it doesn't exactly solve your problem because you don't own the code.

Upvotes: 2

matt
matt

Reputation: 535087

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.

Upvotes: 1

Related Questions