heremaps / gluecodium

Cross-language bindings generator for C++, Java, Swift, and Dart
Apache License 2.0
201 stars 27 forks source link

Expose Swift types to Objective-C #1595

Closed sirnacnud closed 1 month ago

sirnacnud commented 1 month ago

The @Swift(ObjC) was removed in https://github.com/heremaps/gluecodium/pull/739. As a replacement, it says to use @Swift(Attribute="objc") or @Swift(Attribute="objcMembers") instead. But the problem is that the generated Swift class needs to inherit from NSObject in order for these attributes to actually work.

Is there a way with Gluecodium to specify the generated Swift class inherit from NSObject?

Hsilgos commented 1 month ago

I believe we removed compatibility with Objective C because it caused unnecessary complexity. What for do you need it?

sirnacnud commented 1 month ago

If you wanted to use the generated Swift code in code bases which were mixed Objective-C and Swift, this would need to be supported. This is not a blocker for my usage, just was wondering if it was possible.

Thanks for the quick reply.

Hsilgos commented 1 month ago

If you wanted to use the generated Swift code in code bases which were mixed Objective-C and Swift, this would need to be supported. This is not a blocker for my usage, just was wondering if it was possible.

Thanks for the quick reply.

You may try to add additional step to post process generated code and add inheritance from NSObject. We do such for Flutter for imports when we generate code to share between modules/plugins.

sirnacnud commented 1 month ago

If you wanted to use the generated Swift code in code bases which were mixed Objective-C and Swift, this would need to be supported. This is not a blocker for my usage, just was wondering if it was possible. Thanks for the quick reply.

You may try to add additional step to post process generated code and add inheritance from NSObject. We do such for Flutter for imports when we generate code to share between modules/plugins.

Are you able to point me to where you are doing this post processing for Flutter imports? I couldn't fine anything in the repo.

Hsilgos commented 1 month ago

If you wanted to use the generated Swift code in code bases which were mixed Objective-C and Swift, this would need to be supported. This is not a blocker for my usage, just was wondering if it was possible. Thanks for the quick reply.

You may try to add additional step to post process generated code and add inheritance from NSObject. We do such for Flutter for imports when we generate code to share between modules/plugins.

Are you able to point me to where you are doing this post processing for Flutter imports? I couldn't fine anything in the repo.

Sorry, I wasn't clear enough. We do this post processing in out internal project. Actually I see couple of differences in this matter. I don't think that you may avoid patching. The best place where inject your logic with processing the generated files in after call to gluecodium here https://github.com/heremaps/gluecodium/blob/master/cmake/modules/gluecodium/gluecodium/details/runGenerate.cmake#L225