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

[SR-11337] Problem with @objc and renaming #53738

Closed
swift-ci opened this issue Aug 21, 2019 · 0 comments
Closed

[SR-11337] Problem with @objc and renaming #53738

swift-ci opened this issue Aug 21, 2019 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11337
Radar None
Original Reporter barcoded (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

I can verify the problem with Swift 5.0 and 5.1 on the Apple Platform.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: d0e96fae796e98c886ad4fc9cf2aed0a

duplicates:

  • SR-4827 Incorrect result resolving type for Obj-C block

Issue Description:

I've discovered an issue with @objc which I think is a bug. I've discussed the issue at the #swift-lang IRC channel before creating this issue. The situation is the following:

  1. Create a Swift class and add the @objc attribute. Make sure to rename the class for use in Objective C - e.g. @objc(MKCBar)

  2. Next use the class (e.g. `MKCBar`) in an Objective C file (e.g. `MKCFoo`) - like adding a property. In the header use forward declaration (@Class MKCBAR) and in the implementation file import the autogenerated Swift header file.

  3. Add the Objective C file to the bridging header (MKCFoo.h) and thereby making it available to Swift

  4. In another Swift file (Bas.swift) try to create an instance of the Objective C object and try to access the property which is defined using the forward declaration.

  5. Sadly you can't!!!!

  6. Remove the renaming from the @objc attribute and correct the forward declaration and import in the Objective C file.

  7. Now you are able to use the property but lost the ability to rename the class

I've attached a tiny sample project - please look at the Baz.swift file. Alternatively have a look at this blog post which also describes the problem: https://cjwirth.com/tech/circular-references-swift-objc

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

1 participant