Swiftify-Corp / Swiftify

43 stars 24 forks source link

Swiftify does not convert symbols that are renamed in Swift #231

Closed emish closed 2 years ago

emish commented 2 years ago

Lots of compiler errors are left after conversion in the form of: ABCFoo has been renamed to Foo

for types that have a specific objc name

@objc(ABCFoo)
class Foo {}
alex-swiftify commented 2 years ago

@emish I'm trying to get the complete picture here:

Is that correct?

Since Swiftify is not parsing the Swift code, I don't see any way to "fix" this permanently. We do support the NS_SWIFT_NAME macro to specify an alternate Swift name for Objective-C declarations (example). However, I don't see how this could help in renaming usages of the class ABCFoo to Foo in Objective-C.

The only viable way I see to "fix" this would be by making it possible to specify replacements for identifier names in the Preferences dialog. Then you would be able to map a replacement ofABCFoo to Foo. Would this be a feasible solution?

emish commented 2 years ago

@alex-swiftify Thanks for the reply.

Your understanding is correct.

Since Swiftify is not parsing Swift code in the project this makes sense. I was expecting that Swiftify did some parsing to rename symbols that are defined in Swift and are provided with an @objc() name.

I'm thankful for your suggestion to create a replacements list in the Preferences dialog, however, I'm not sure that I would use it as it would feel cumbersome for long lists of dozens or hundreds of renamed symbols. Generally, I think fix-its would handle this scenario in Xcode but because I am building large projects with Bazel I do not have that luxury at this time.

I would be happy to close this issue if you do not feel it is appropriate to introduce some level of parsing into Swiftify Converter.

alex-swiftify commented 2 years ago

@emish I gave it a thought, and it's pretty unlikely that we will implement parsing of the Swift files in the nearest time, at least unless we get more votes for this feature. It's interesting that you've got dozens or hundreds of such cases in your project. For my better understanding, why is that the case? I guess you've had a convention e.g. to prefix all class names with your company's XYZ prefix in Objective-C, but not in Swift?

If the above is your actual use case, we've got other reports like this one. An option to remove the prefix from Objective-C type names is possible to add if that's used widely and consistently within your project.

alex-swiftify commented 2 years ago

@emish I'm closing this issue in favor of https://swiftify.atlassian.net/browse/SWE-442 (since I got no reply or clarification from you). However, I'd appreciate a quick note if adding an option to remove a specific class name prefix would be an acceptable solution for the issue you described.