Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protocols with same name as class #213

Open
AlexanderJ opened this issue Mar 28, 2022 · 6 comments
Open

Protocols with same name as class #213

AlexanderJ opened this issue Mar 28, 2022 · 6 comments

Comments

@AlexanderJ
Copy link

If I use the same name for protocol and class in Objective-C (like many NS types, e.g. NSObject) the name of the protocol should get a Protocol suffix (Xcode also bridges objective-c protocols like that). This only applies if the code contains @protocol and @interface with the same exact name. Thus scanning all headers for this locally and sending the information to the translation is important.

Example: https://swiftify.me/lc8ui2

I would expect a Blub class and a BlubProtocol protocol.

@AlexanderJ
Copy link
Author

I also reported this issue via email some time ago, but I didn't find a corresponding issue. I consider this high priority for us.

@alex-swiftify
Copy link
Member

@AlexanderJ Copying over the reply that I've sent you in https://swiftify.zendesk.com/agent/tickets/2538
The best I could suggest for now is renaming the protocols in your Objective-C code before the conversion.

Protocol name matching class name.
We may potentially rename such protocols appending a suffix i.e. Protocol, like with NSObject -> NSObjectProtocol.
While this appears possible to implement, I foresee a potential problem with naming consistency among several source files within the project.

For example, when you convert one pair of header/source files, it may contain a protocol name matching class name, thus the protocol will be renamed.
However, if another source file (converted separately) references only the protocol name, but not the class name,
the converter wouldn't know about the naming collision, thus the protocol won't be renamed.

Hence I don't see an easy solution here, unfortunately.
Processing absolutely all source files when you select and convert only 1-2 files within the project is only feasible in the Offline Converter,
since sending the whole project to the server in the cloud version doesn't look like a feasible solution.

@AlexanderJ
Copy link
Author

This is unfortunately not always possible. One of the FW used here JSONModel requires that protocol and class have the same name.

@alex-swiftify
Copy link
Member

@AlexanderJ The case is understandable, but I don't see an easy or feasible solution here, unfortunately.
Especially with each usage of "Blub", it's too difficult for the converter to infer whether a specific usage should be renamed to "BulbProtocol" or not.

Scanning of all headers may be implemented at some point in time, but only in the Offline Converter version, since sending all headers to the API would be too time and bandwidth-consuming.

@AlexanderJ
Copy link
Author

I don't think it would be necessary to transfer all the files. Scanning all files locally and transmitting only the information required to do the conversion correctly would suffice (e.g. just send the information that the class is available as protocol and as class). I don't think the code scanner is similar problematic to install on the customer site as the code converter.

With this information you can translate NSArray and id as protocol and all other uses as class. That would at least compile. If I want to convert additional classes back to protocol I still have the option to do so manually.

@alex-swiftify
Copy link
Member

@AlexanderJ Understandable, although implementing this looks pretty complex compared to the other improvements, so unfortunately I cannot guarantee this will be completed anytime soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants