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
[SR-14381] @objc & @objcMembers attributes break compilation on Windows #56739
Comments
You can pass the compiler flags |
This is expected, and dare I say, desired behavior. The default on non-Apple targets is that the ObjC interop is disabled. You would need to provide your own build of an ABI compatible ObjC runtime if you wish to use the ObjC interop. You can enable it with the |
Comment by Eugene Gubin (JIRA) I was told it's a bug 🙂 Details: https://forums.swift.org/t/objc-attribute-windows/46787 |
I don't consider this a bug, it is intentional. Objective-C interop is non-trivial, and a massive undertaking. |
Comment by Eugene Gubin (JIRA) @compnerd Sorry, when I said `bug` I mean what `@objc` should be just ignored on Windows since Objective-C runtime is not supported there. One can not use conditional defines to turn these annotations off. It breaks declaration. ``` #if os(Darwin) #end class MyClass: NSObject { } ``` |
Eugene Gubin (JIRA User) - I think that is the confusion. The runtime is not unsupported, it is unavailable by default. If you have a build of a compatible ObjC runtime, you can enable the ObjC interop via the |
Comment by Eugene Gubin (JIRA) @compnerd, thanks for clarification! But what to do with these @objc annotations in cross-platform code? As shown in the example above it could force you to repeat an entire declaration. I think it would be good to have a way to ignore these annotations on platforms there ObjC runtime is not available. |
Changes like that require an evolution proposal, along with an implementation. For |
It is a PITA to when trying to cross check same code on Windows and OSX. :-) |
SE-0367 should fix the issue. |
I have the issue I tried:
... but as I would expect, I have still got the same error. I had to use:
which is quite verbose in the code when you go from this easily readable code:
to this one:
An alternative would be to use |
I can see where people would want to be able to write Swift frameworks in such a way that on ObjC-supporting platforms, the types would be available from ObjC. And yes, having As @compnerd pointed out above, however, this would be a change to the existing language behavior. As such, we cannot make such a change without first discussing it on the Swift forums and having a Swift Evolution proposal reviewed by the Swift Language Steering Group. For a change like this, the proposal would not need to be very involved, but we cannot make such a change without going through this process, which allows people who may have other use cases than yours to debate what the full impact would be. If you wish to pursue doing this, the process is open to anyone who wants to participate. I'd be happy to give you pointers on how to proceed. |
Just to mention, |
Attachment: Download
Environment
Windows 10, swift-DEVELOPMENT-SNAPSHOT-2021-03-02-a-windows10
Additional Detail from JIRA
md5: 3bc38c5bc812b76bec20dd2017e83d57
is blocked by:
Issue Description:
Both @objc & @objcMembers attributes break compilation on Windows
Steps to reproduce: download the attachment, unpack and build.
Result:
The text was updated successfully, but these errors were encountered: